https://kotlinlang.org logo
Title
b

Bino

08/10/2022, 7:43 AM
:compose: 🖥️ Does anyone has experience with Compose for Desktop and using a native c library? I was able to load the native library desktop
val resources = File(System.getProperty("compose.application.resources.dir")).parent
System.load(File(resources, "libutil.dylib").absolutePath)
But I don’t know how I can access it.
@Emmanuel loading the
.dylib
isn’t an issue. But I don’t know, how to access it via an JNI or c-interop call from inside kotlin.
r

rnett

08/10/2022, 10:54 PM
Same as you would in Java, via JNI. In fact, you can write your JNI code in Java and just call it from Kotlin. See https://kotlinlang.org/docs/java-interop.html#using-jni-with-kotlin
l

Landry Norris

08/11/2022, 12:50 AM
You can also write K/N code that calls into the library and a Kotlin object to call into your K/N like in https://github.com/LandryNorris/JniUtils sample module.
b

Bino

08/11/2022, 8:44 AM
ah sure, I had to add
JNIEXPORT
and
JNICALL
to the library to get access from outside.🎉