Kotlin Help

Platform libraries

To provide access to native services of operating systems, the Kotlin/Native distribution includes a set of prebuilt libraries specific to each target. These are called platform libraries.

The packages from platform libraries are available by default. You don't need to specify additional link options to use them. The Kotlin/Native compiler automatically detects which platform libraries are accessed and links the necessary ones.

However, platform libraries in the compiler distribution are merely wrappers and bindings to the native libraries. That means you need to install native libraries themselves (.so, .a, .dylib, .dll, and so on) on your local machine.

POSIX bindings

Kotlin provides the POSIX platform library for all UNIX- and Windows-based targets, including Android and iOS. These platform libraries contain bindings to the platform's implementation, which follows the POSIX standard.

To use the library, import it into your project:

import platform.posix.*

You can explore the contents of the posix.def file for each supported platform here:

The POSIX platform library is not available for the WebAssembly target.

Kotlin/Native provides bindings for various popular native libraries that are commonly used on different platforms, such as OpenGL, zlib, and Foundation.

On Apple platforms, the objc library is included to enable interoperability with Objective-C APIs.

You can explore the native libraries available for Kotlin/Native targets in your compiler distribution, depending on your setup:

  • If you installed a standalone Kotlin/Native compiler:

    1. Go to the unpacked archive with the compiler distribution, for example, kotlin-native-prebuilt-macos-aarch64-2.1.0.

    2. Navigate to the klib/platform directory.

    3. Choose the folder with the corresponding target.

  • If you use the Kotlin plugin in your IDE (bundled with IntelliJ IDEA and Android Studio):

    1. In your command line tool, run the following to navigate to the .konan folder:

      ~/.konan/
      %USERPROFILE%\.konan
    2. Open the Kotlin/Native compiler distribution, for example, kotlin-native-prebuilt-macos-aarch64-2.1.0.

    3. Navigate to the klib/platform directory.

    4. Choose the folder with the corresponding target.

What's next

Learn more about interoperability with Swift/Objective-C

Last modified: 13 February 2025