Kotlin Native Shared Library Exported Function


#1

I’m sure this has already been asked, sorry if I can’t find it. But how do I export a specific top-level function from Kotlin native in my dynamic shared library? I see my normal code is exported under an “exported symbols” pseudo-struct-namespace. I see c-interop code there are interop stubs that take header functions and delegate to “bridge” functions which are marked “private external”. I see the python extension example that uses a C file to bridge.

So, for example, say I wanted to implement/expose JNI_OnLoad, how would I? I see this code generated via interop:

fun JNI_OnLoad(vm: CValuesRef<JavaVMVar>?, reserved: CValuesRef<*>?): jint {
    memScoped {
        return kniBridge3(vm?.getPointer(memScope).rawValue, reserved?.getPointer(memScope).rawValue)
    }
}

Is there some way I can hand edit this? Has anyone ever manually exposed a function from a DLL before?


#2

Issue created: https://github.com/JetBrains/kotlin-native/issues/1220


#3

For anyone else curious, I updated the issue with what I ended up doing which is basically just passing Longs to the Kotlin side. I placed a PoC at https://github.com/cretz/kotlin-native-sample-agent/.