I have a C library that I need to use from android and iOS, so my idea is to create a multiplatform module that would wrap the library to use it from both implementations.
In other hand, I've seen a sample where C code is used by kotlin native: https://theprogrammershangout.com/resources/kotlin/native/creating-c-bindings.md/
Also this one from kotlin documentation: https://kotlinlang.org/docs/native-c-interop.html
Would that be possible to make that interoperability work with jvm and iOS?
CodePudding user response:
You cannot directly interop with C from Kotlin/Native (using cinterop). Your C library would need to expose an extern C
version of itself, or you'd need to create a C compatible bride to your C library, and let cinterop look at that.
It might be more natural to wrap that with an Objective-C interface rather than a C one, but that will obviously depend on what the library does and your comfort level with C vs Objective-C.