How do I run my program?
Define a top-level function
fun main(args: Array<String>) or just
fun main() if you are not interested in passed arguments, please ensure it's not in a package. Also, compiler switch
-entry could be used to make any function taking
Array<String> or no arguments and return
Unit as an entry point.
What is Kotlin/Native memory management model?
Kotlin/Native uses an automated memory management scheme that is similar to what Java or Swift provide.
How do I create a shared library?
-produce dynamic compiler switch, or
binaries.sharedLib() in Gradle.
It will produce a platform-specific shared object (
.so on Linux,
.dylib on macOS, and
.dll on Windows targets) and a C language header, allowing the use of all public APIs available in your Kotlin/Native program from C/C++ code.
How do I create a static library or an object file?
-produce static compiler switch, or
binaries.staticLib() in Gradle.
It will produce a platform-specific static object (
.a library format) and a C language header, allowing you to use all the public APIs available in your Kotlin/Native program from C/C++ code.
How do I run Kotlin/Native behind a corporate proxy?
As Kotlin/Native needs to download a platform specific toolchain, you need to specify
-Dhttp.proxyHost=xxx -Dhttp.proxyPort=xxx as the compiler's or
gradlew arguments, or set it via the
JAVA_OPTS environment variable.
How do I specify a custom Objective-C prefix/name for my Kotlin framework?
-module-name compiler option or matching Gradle DSL statement.
How do I rename the iOS framework?
The default name is for an iOS framework is
<project name>.framework. To set a custom name, use the
baseName option. This will also set the module name.
How do I enable bitcode for my Kotlin framework?
By default gradle plugin adds it on iOS target.
For debug build it embeds placeholder LLVM IR data as a marker.
For release build it embeds bitcode as data.
Or commandline arguments:
-Xembed-bitcode (for release) and
Setting this in a Gradle DSL:
These options have nearly the same effect as clang's
-fembed-bitcode-marker and swiftc's
Why do I see InvalidMutabilityException?
It likely happens, because you are trying to mutate a frozen object. An object can transfer to the frozen state either explicitly, as objects reachable from objects on which the
kotlin.native.concurrent.freeze is called, or implicitly (i.e. reachable from
enum or global singleton object - see the next question).
How do I make a singleton object mutable?
Currently, singleton objects are immutable (i.e. frozen after creation), and it's generally considered good practise to have the global state immutable. If for some reason you need a mutable state inside such an object, use the
@konan.ThreadLocal annotation on the object. Also, the
kotlin.native.concurrent.AtomicReference class could be used to store different pointers to frozen objects in a frozen object and automatically update them.
How can I compile my project with unreleased versions of Kotlin/Native?
First, please consider trying preview versions.