Updated LIBRARIES.md
This commit is contained in:
committed by
alexander-gorshenev
parent
aa816d1097
commit
2b1c607ef2
+28
-21
@@ -31,17 +31,19 @@ the above command will produce a `program.kexe` out of `qux.kt` and `bar.klib`
|
|||||||
## cinterop tool specifics
|
## cinterop tool specifics
|
||||||
|
|
||||||
The **cinterop** tool produces `.klib` wrappers for native libraries as its main output.
|
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
|
For example, using the simple `libgit2.def` native library definition file provided in your Kotlin/Native distribution
|
||||||
|
|
||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cinterop -def ./samples/csvparser/src/main/c_interop/stdio.def -o stdio
|
$ cinterop -def samples/gitchurn/src/main/c_interop/libgit2.def -compilerOpts -I/usr/local/include -o libgit2
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
we will obtain `stdio.klib`.
|
we will obtain `libgit2.klib`.
|
||||||
|
|
||||||
|
See more details in [INTEROP.md](INTEROP.md)
|
||||||
|
|
||||||
|
|
||||||
## klib utility
|
## klib utility
|
||||||
@@ -103,12 +105,19 @@ $ klib <command> <name> -repository <directory>
|
|||||||
|
|
||||||
## Several examples
|
## Several examples
|
||||||
|
|
||||||
First let's create a library:
|
First let's create a library.
|
||||||
|
Place the tiny library source code into `kotlinizer.kt`:
|
||||||
|
|
||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
package kotlinizer
|
||||||
|
val String.kotlinized
|
||||||
|
get() = "Kotlin $this"
|
||||||
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cinterop -h /usr/include/math.h -pkg libc.math -o math
|
$ kotlinc kotlinizer.kt -p library -o kotlinizer
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -118,8 +127,8 @@ The library has been created in the current directory:
|
|||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ls math.klib
|
$ ls kotlinizer.klib
|
||||||
math.klib
|
kotlinizer.klib
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -129,39 +138,40 @@ Now let's check out the contents of the library:
|
|||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ klib contents math
|
$ klib contents kotlinizer
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
We can install `math` to the default repository:
|
We can install `kotlinizer` to the default repository:
|
||||||
|
|
||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ klib install math
|
$ klib install kotlinizer
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Remove any traces of it and its build process from the current directory:
|
Remove any traces of it from the current directory:
|
||||||
|
|
||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ rm -rf ./math*
|
$ rm kotlinizer.klib
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Create a very short program and place it into a `sin.kt` :
|
Create a very short program and place it into a `use.kt` :
|
||||||
|
|
||||||
<div class="sample" markdown="1" theme="idea" data-highlight-only>
|
<div class="sample" markdown="1" theme="idea" data-highlight-only>
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
import libc.math.*
|
import kotlinizer.*
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
println(sin(2.0))
|
println("Hello, ${"world".kotlinized}!")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -172,7 +182,7 @@ Now compile the program linking with the library we have just created:
|
|||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ kotlinc sin.kt -l math -o mysin
|
$ kotlinc use.kt -l kotlinizer -o kohello
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -182,8 +192,8 @@ And run the program:
|
|||||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ./mysin.kexe
|
$ ./kohello.kexe
|
||||||
0.9092974268256817
|
Hello, Kotlin world!
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -204,11 +214,8 @@ When given a `-library foo` flag, the compiler searches the `foo` library in the
|
|||||||
|
|
||||||
* Libraries installed in `$installation/klib` directory.
|
* Libraries installed in `$installation/klib` directory.
|
||||||
|
|
||||||
|
|
||||||
## The library format
|
## The library format
|
||||||
|
|
||||||
**WARNING**: the library format is *very* preliminary. It is subject to change right under your fingertips. And it can include changes which will make it incompatible between releases at least until Kotlin/Native is stabilized.
|
|
||||||
|
|
||||||
Kotlin/Native libraries are zip files containing a predefined
|
Kotlin/Native libraries are zip files containing a predefined
|
||||||
directory structure, with the following layout:
|
directory structure, with the following layout:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user