is there any guide on making a kotlin native lib t...
# kotlin-native
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
that's for generating c headers from kotlin. I'm wanting to make a library that others can use
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).
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: 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…
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 ( ) • LVGL KT Drivers ( ) • KMQTT Client ( ) • Ktor Server ( ) • Ktor Client ( )