is there any guide on making a kotlin native lib t...
# kotlin-native
z
is there any guide on making a kotlin native lib that uses cinterop? basically I wanna add documentation and make use of kotlin to make it more friendly to use. I'm not sure if I would somehow include the headers, the def file, or maybe something else
z
that's for generating c headers from kotlin. I'm wanting to make a library that others can use
n
The Objective C stuff has nothing to do with C interop, and is specific to Apple platforms (not applicable to other platforms like Linux/Embedded Linux for example).
k
I’m giving a talk tomorrow on this 🙂
If you have the C and header files, and you want to make a library that somebody can use (if I understand what you’re saying), you can essentially make a library that uses cinterop to generate the Kotlin calls, then you need to build the c source and (ideally) put that in your klib. The using the library doesn’t involve exotic config on the consuming side. However, just cinterop produced c-like Kotlin, so you might want to add some more Kotlin-friendly calls on top. Kind of depends on your goal.
We absolutely make no promises on supporting this library, but it’s designed to make compiling c/c++/objc and putting that binary into klibs easier (cinterop is a separate step).
👍 1
Public example here: https://github.com/cashapp/zipline/blob/trunk/zipline/build.gradle.kts#L157. Alternatively, you need to do your own clang config, which isn’t terrible, but still.
This should work for linux targets as well, but the nature of my daily work means I don’t do that much. Windows, less sure…
n
Most of the C interop that takes place in Kotlin Native libraries isn't mobile development related. More C interop examples can be found with the Linux targets than with any other Kotlin Native targets.
Below are some examples of C interop with Kotlin Native libraries: • GUI Vista Core ( https://gitlab.com/gui-vista/guivista-core ) • LVGL KT Drivers ( https://gitlab.com/embed-soft/lvgl-kt/lvgl-kt-drivers ) • KMQTT Client ( https://gitlab.com/napperley/kmqtt-client ) • Ktor Server ( https://github.com/ktorio/ktor/tree/main/ktor-server ) • Ktor Client ( https://github.com/ktorio/ktor/tree/main/ktor-client )