Kotlin/Native
Explore how to use Kotlin/Native to compile Kotlin code for native platforms such as MacOS, Windows, and Linux. Understand how to interoperate with C libraries by using Kotlin's cinterop tool to generate Kotlin signatures from C headers, enabling native executable creation without a virtual machine.
We'll cover the following...
In addition to JVM, JavaScript, Android devices, iOS, and Raspberry Pi, you can target your Kotlin code to native platforms like Windows, Mac OS, and Linux. The Kotlin compiler’s front end compiles your Kotlin code to an intermediate representation. Kotlin/Native is an LLVM-based back end of the compiler that targets the intermediate representation to self-contained programs that can run natively without a virtual machine. Your Kotlin code can interoperate with native libraries—for example, code written using the C language, Objective-C, and Swift. You can use this option to create fast running native applications and to interoperate with native libraries.
In this appendix, we’ll take a look at a small example that illustrates compiling Kotlin code to target MacOS. To target the example to other operating systems, refer to the toolchain requirements on the Kotlin/Native website.
Downloading native environment
To compile Kotlin code to native platform, you need the Kotlin/Native compiler. Download it from the binary distribution ...