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
nfrankel
10/26/2019, 7:06 PM
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
voldyman
10/26/2019, 7:10 PM
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
nfrankel
10/26/2019, 7:11 PM
nope
i tried to be as far from c/c++ as possible 😉
by the way, this is not kotlin specific 😅
m
Markus Böck
10/26/2019, 8:44 PM
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
voldyman
10/26/2019, 8:56 PM
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
Markus Böck
10/26/2019, 8:58 PM
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