平台库
为了提供对操作系统原生服务的访问,Kotlin/Native 发行版包含了一组为每个目标平台预构建的库。 这些被称为平台库。
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 绑定
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.*
The
platform.posix
contents differ across platforms because of variations in POSIX implementations.{style="note"}
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.
Popular native libraries
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:
- Go to the unpacked archive with the compiler distribution, for example,
kotlin-native-prebuilt-macos-aarch64-2.1.0
. - Navigate to the
klib/platform
directory. - Choose the folder with the corresponding target.
- Go to the unpacked archive with the compiler distribution, for example,
If you use the Kotlin plugin in your IDE (bundled with IntelliJ IDEA and Android Studio):
- In your command line tool, run the following to navigate to the
.konan
folder:
- In your command line tool, run the following to navigate to the
【macOS and Linux】
~/.konan/
【Windows】
%\USERPROFILE%\.konan
- Open the Kotlin/Native compiler distribution, for example,
kotlin-native-prebuilt-macos-aarch64-2.1.0
. - Navigate to the
klib/platform
directory. - Choose the folder with the corresponding target.
If you'd like to explore the definition file for each supported platform library: in the compiler distribution folder, navigate to the
konan/platformDef
directory and choose the necessary target.{style="tip"}