https://github.com/datkt/c-pointer-example
A simple example demonstrating the use of C pointers in Kotlin/Native
https://github.com/datkt/c-pointer-example
c example konanc kotlin native pointer
Last synced: about 2 months ago
JSON representation
A simple example demonstrating the use of C pointers in Kotlin/Native
- Host: GitHub
- URL: https://github.com/datkt/c-pointer-example
- Owner: datkt
- License: mit
- Created: 2018-10-31T18:21:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-31T20:51:31.000Z (over 7 years ago)
- Last Synced: 2025-04-11T05:37:38.435Z (about 1 year ago)
- Topics: c, example, konanc, kotlin, native, pointer
- Language: Makefile
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
c-pointer-example
=================
A simple example demonstrating the use of C pointers in Kotlin/Native.
## Background
The files needed to build this example can be built by running the
`make` (or `make build`) command. This will build the `pointer.klib` and
`main.kexe` files by using the `cinterop` command on `pointer.def` to generate
the Kotlin source, compiled binary, and the resulting `klib` file from
`pointer.h`. The `konanc` command then compiles the `main.kt` file that
links `pointer.klib` to a Kotlin executable `main.kexe`. The program is
then executable by invoking `./main.kexe`. This should print the
following output.
```
(int) 1234
(string) hello
```
## Building
To build the entire program, run `make build` which results in a
`main.kexe` program executable. The `Makefile` targets for various files
are documented below.
### `make build`
Builds everything.
### `make pointer.klib`
Builds the Kotlin library `pointer.klib` that can be linked in the
`konanc` command.
### `make main.kexe`
Builds the Kotlin program executable `main.kexe`. Depends on
`main pointer.klib`.
## See Also
* https://github.com/JetBrains/kotlin-native
* https://kotlinlang.org/docs/reference/native-overview.html
* https://rosettacode.org/wiki/Pointers_and_references#Kotlin
* https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/index.html
* https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/mem-scoped.html
## License
MIT