I have a C++ library that builds with CMake and i ...
# announcements
v
I have a C++ library that builds with CMake and i am trying to write a GUI for it in kotlin and i am assuming i'll need to write JNI bindings for the library. i can't figure out how setup the build system for a project with C++ and kotlin/java for the JNI bindings. Any help would be appreciated.
n
i think jni is dead since ages if i remember well, there’s something called jna that should be its betterment https://github.com/java-native-access/jna in all cases, good luck last time i looked it was a mess
v
oh interesting, thanks i'll take a deeper look into JNA. Do you know of projects that use CMake based cpp libs with kotlin and jna?
n
nope i tried to be as far from c/c++ as possible 😉 by the way, this is not kotlin specific 😅
m
JNA and JNI is not the same. JNA only gives you one way communication with Java only able to call native code. Native code wont be able to call java code. Also JNA is 10x slower so if performance matters use JNI
It looks like if you want pure Kotlin code with no Java that youll have to use the external keyword for functions and then create the header on the C++ side yourself
v
yeah, i've been reading up on JNA & JNI and might have to go with JNI. the problem i am trying to tackle right now is getting the .so/.dylib in the same jar
m
I always put it into the resource folder and then for the static initializer of the first class loaded I'd load it from resources write it into a temp directory and then load it explicitly
👍 1