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
|
||||
|
||||
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">
|
||||
|
||||
```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>
|
||||
|
||||
we will obtain `stdio.klib`.
|
||||
we will obtain `libgit2.klib`.
|
||||
|
||||
See more details in [INTEROP.md](INTEROP.md)
|
||||
|
||||
|
||||
## klib utility
|
||||
@@ -103,12 +105,19 @@ $ klib <command> <name> -repository <directory>
|
||||
|
||||
## 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">
|
||||
|
||||
```kotlin
|
||||
package kotlinizer
|
||||
val String.kotlinized
|
||||
get() = "Kotlin $this"
|
||||
```
|
||||
|
||||
```bash
|
||||
$ cinterop -h /usr/include/math.h -pkg libc.math -o math
|
||||
$ kotlinc kotlinizer.kt -p library -o kotlinizer
|
||||
```
|
||||
|
||||
</div>
|
||||
@@ -118,8 +127,8 @@ The library has been created in the current directory:
|
||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||
|
||||
```bash
|
||||
$ ls math.klib
|
||||
math.klib
|
||||
$ ls kotlinizer.klib
|
||||
kotlinizer.klib
|
||||
```
|
||||
|
||||
</div>
|
||||
@@ -129,39 +138,40 @@ Now let's check out the contents of the library:
|
||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||
|
||||
```bash
|
||||
$ klib contents math
|
||||
$ klib contents kotlinizer
|
||||
```
|
||||
|
||||
</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">
|
||||
|
||||
```bash
|
||||
$ klib install math
|
||||
$ klib install kotlinizer
|
||||
```
|
||||
|
||||
</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">
|
||||
|
||||
```bash
|
||||
$ rm -rf ./math*
|
||||
$ rm kotlinizer.klib
|
||||
```
|
||||
|
||||
</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>
|
||||
|
||||
```kotlin
|
||||
import libc.math.*
|
||||
import kotlinizer.*
|
||||
|
||||
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">
|
||||
|
||||
```bash
|
||||
$ kotlinc sin.kt -l math -o mysin
|
||||
$ kotlinc use.kt -l kotlinizer -o kohello
|
||||
```
|
||||
|
||||
</div>
|
||||
@@ -182,8 +192,8 @@ And run the program:
|
||||
<div class="sample" markdown="1" theme="idea" mode="shell">
|
||||
|
||||
```bash
|
||||
$ ./mysin.kexe
|
||||
0.9092974268256817
|
||||
$ ./kohello.kexe
|
||||
Hello, Kotlin world!
|
||||
```
|
||||
|
||||
</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.
|
||||
|
||||
|
||||
## 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
|
||||
directory structure, with the following layout:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user