# Kotlin/Native libraries ## Library compilation You can use your project's build file or the Kotlin/Native compiler to produce a `*.klib` artifact for your library. ### Using Gradle build file You can compile a `*.klib` library artifact by specifying a [Kotlin/Native target](native-target-support.html) in your Gradle build file: 1. In your `build.gradle(.kts)` file, declare at least one Kotlin/Native target. For example: ```KOTLIN // build.gradle.kts plugins { kotlin("multiplatform") version "2.4.21" } kotlin { macosArm64() // on macOS // linuxArm64() // on Linux // mingwX64() // on Windows } ``` 2. Run the `Klib` task. For example: ```BASH ./gradlew macosArm64Klib ``` Gradle automatically compiles source files for that target and produces the `.klib` artifact in the project's `build/libs` directory. ### Using Kotlin/Native compiler To produce a library with the Kotlin/Native compiler: 1. [Download and install the Kotlin/Native compiler.](native-get-started.html#download-and-install-the-compiler) 2. To compile a Kotlin/Native source file into a library, use the `-produce library` or `-p library` option: ```BASH kotlinc-native foo.kt -p library -o bar ``` This command compiles the contents of the `foo.kt` file into a library with the name `bar`, producing a `bar.klib` artifact. 3. To link another file to a library, use the `-library ` or `-l ` option. For example: ```BASH kotlinc-native qux.kt -l bar ``` This command compiles the contents of the `qux.kt` source file and the `bar.klib` library and produces the `program.kexe` final executable binary. ## klib utility The klib library management utility allows you to inspect libraries using the following syntax: ```BASH klib [