Hello, I'm new to native, is it possible to use a ...
# kotlin-native
a
Hello, I'm new to native, is it possible to use a c++ library from kotlin ? Use case : Multiplatform kotlin library that targets native would be able to use existing c++ library in its native code definition (since most Kotlin Multiplatform library are JVM or JS only)
b
Only via C. Direct cpp interop is postponed
a
In general is it the recommended approach (to use C interop and try to call c libs)? Or is it better to look for ways the users of your kotlin multiplatform lib could call the JS target instead of native ? Native seems to be still relatively new in the ecosystem, not a lot of KMP seem to offer it
From my understanding this means that if you want to call a c++ lib then trying to adapt your lib users to use the JS target might be your only option.
b
Not sure how cpp relates to js, sorry 😀
a
What I'm saying is maybe if your library users are c++ apps, then maybe it's better to ditch native and target JS (Assuming c++ can call JS). Would have to double check but pretty sure c++ can call JS
b
But kotlin really cares only about the headers. Some cpp issues provide c headers so see if your lib has that
a
Ok thanks
b
Even if cpp can call js, that would be a significant performance hit and as such I'd personally try to avoid it.
a
Yes for sure, but at least that'd be a solution to start off with.
b
I think writing your own C layer to interop between the two would be a better way to go
a
Interesting idea, I would need to define C headers for the kotlin lib and call my c++ lib from
.c
files?
b
Something like that. I've never actually done it myself, just an idea.
👍 1