diff --git a/LIBRARIES.md b/LIBRARIES.md index 1db3a522113..3366351b033 100644 --- a/LIBRARIES.md +++ b/LIBRARIES.md @@ -4,13 +4,26 @@ To produce a library with the Kotlin/Native compiler use the `-produce library` or `-p library` flag. For example: - $ kotlinc foo.kt -p library -o bar +
+ +```bash +$ kotlinc foo.kt -p library -o bar +``` + +
the above command will produce a `bar.klib` with the compiled contents of `foo.kt`. To link to a library use the `-library ` or `-l ` flag. For example: - $ kotlinc qux.kt -l bar +
+ +```bash +$ kotlinc qux.kt -l bar +``` + +
+ the above command will produce a `program.kexe` out of `qux.kt` and `bar.klib` @@ -20,7 +33,13 @@ the above command will produce a `program.kexe` out of `qux.kt` and `bar.klib` The **cinterop** tool produces `.klib` wrappers for native libraries as its main output. For example, using the simple `stdio.def` native library definition file provided in your Kotlin/Native distribution - $ cinterop -def ./samples/csvparser/src/main/c_interop/stdio.def -o stdio +
+ +```bash +$ cinterop -def ./samples/csvparser/src/main/c_interop/stdio.def -o stdio +``` + +
we will obtain `stdio.klib`. @@ -33,63 +52,141 @@ The following commands are available. To list library contents: - $ klib contents +
+ +```bash +$ klib contents +``` + +
To inspect the bookkeeping details of the library - $ klib info +
+ +```bash +$ klib info +``` + +
To install the library to the default location use - $ klib install +
+ +```bash +$ klib install +``` + +
To remove the library from the default repository use - $ klib remove +
-All of the above commands accept an additional `-repository ` argument for specifying a repository different to the default one. +```bash +$ klib remove +``` - $ klib -repository +
+ +All of the above commands accept an additional `-repository ` argument for specifying a repository different to the default one. + +
+ +```bash +$ klib -repository +``` + +
## Several examples First let's create a library: - $ cinterop -h /usr/include/math.h -pkg libc.math -o math +
+ +```bash +$ cinterop -h /usr/include/math.h -pkg libc.math -o math +``` + +
The library has been created in the current directory: - $ ls math.klib - math.klib +
+ +```bash +$ ls math.klib +math.klib +``` + +
Now let's check out the contents of the library: - $ klib contents math +
+ +```bash +$ klib contents math +``` + +
We can install `math` to the default repository: - $ klib install math +
+ +```bash +$ klib install math +``` + +
Remove any traces of it and its build process from the current directory: - $ rm -rf ./math* +
+ +```bash +$ rm -rf ./math* +``` + +
Create a very short program and place it into a `sin.kt` : - import libc.math.* - fun main(args: Array) { - println(sin(2.0)) - } +
+ +```kotlin +import libc.math.* +fun main(args: Array) { + println(sin(2.0)) +} +``` + +
Now compile the program linking with the library we have just created: - $ kotlinc sin.kt -l math -o mysin +
+ +```bash +$ kotlinc sin.kt -l math -o mysin +``` + +
And run the program: - $ ./mysin.kexe - 0.9092974268256817 +
+ +```bash +$ ./mysin.kexe +0.9092974268256817 +``` + +
Have fun! @@ -117,7 +214,7 @@ directory structure, with the following layout: **foo.klib** when unpacked as **foo/** gives us: -``` +```yml - foo/ - targets/ - $platform/ diff --git a/PLATFORM_LIBS.md b/PLATFORM_LIBS.md index 5139c6fc60c..c31f140796a 100644 --- a/PLATFORM_LIBS.md +++ b/PLATFORM_LIBS.md @@ -28,7 +28,6 @@ Note that the content of `platform.posix` is NOT identical on different platforms, in the same way as different `POSIX` implementations are a little different. - ### Popular native libraries