I tried generating a wrapper lib, but I get ugly g...
# chicago
b
I tried generating a wrapper lib, but I get ugly gcc errors "/usr/lib/jvm/java-13-openjdk/include/linux/jni_md.h3727: error: expected ‘,’ or ‘;’ before ‘__attribute__’ 37 | #define JNIEXPORT __attribute__((visibility("default")))"
m
Hmm, I see you're using openjdk 13, I'm wondering if this is an incompatibility with JNI on that version. I've only gone up to 12, so not sure. Can you share the library that you're wrapping?
Also, how are you generating the header file?
b
by hand
ok I found that I was missing a ;
I was confused by the error I got it to work for one function
the problem is that the library I'm wrapping is proprietary
I just have a header file and an example they did of a python c interop example
m
Ah OK. Yeah, manual is what I've done >8. They deprecated javah in later versions of the JDK, so automatic generation tends to be a bit more difficult, though it's still possible, I believe.
b
the header I have is a c++ header
so doesn't help too much either
m
Yeah. Actually, I just looked it up since I couldn't remember the replacement, and it's now
javac -h . NativeLib.java
It targets the
.java
source file instead of the compiled
.class
files
b
switching between kotlin and c code is somewhat mind bending
wait pointer, malloc, no just var
m
🤣
Yeah, context switching can be a little intense!
b
so much wizardry
but it seems to work
m
message has been deleted
b
that machine is producing 1g every 5min
I need to convert that data
and there is no real thing for linux machines except a docker+wine approach
m
ouch. docker+wine = messy?
Oh, in case you find it useful, here's the github repo I put together for my talk last year at Kotlin Everywhere: https://github.com/mattmoore/kotlin-cinterop-talk
b
thx!
I have a function like that:
Copy code
int baf2sql_array_get_num_elements(u_int64_t, u_int64_t, u_int64_t *);
what would you recommend to wrap it
the u_int64_t one is where the number of elements will be written
should make a class maybe instead
and return that
m
Oh yeah. Might be good to wrap it. That function kinda hurts my eyes lol.
That’s always the thing with interop. Making things interface is great but it helps to make a wrapper to make it more Kotlin-like and easier for other devs not familiar with the native library.
I’m actually going through this with an open source project where I’m bringing tensorflow to Kotlin JVM and native. I’ll send that over to you soon in case it helps to see how I’m building a wrapper around the interop calls to make it easier to use.
b
I got it with a jobject
created a class
and I instanciated a new object
(calling its custom constructor)
maybe I could have used a primary constructor
I will try that when I get it running
and I agree, using the wrapper to prepare stuff for kotlin is much easier