Calling Go Function from java using JNI: Library Not loaded

60 Views Asked by At

I am trying to call a go function from scala code using JNI . The function in question is as follows

//export Java_jniroute_TestJNI_printDisplay
func Java_jniroute_TestJNI_printDisplay(env *C.JNIEnv, obj C.jobject) {
size := C.jx_GetIntArrayElements(env, val1, (*C.jboolean)(nil))
fmt.Println("hello from go")

To enable go call jx_GetIntArrayElements i already created a wrapper C lib with code

#include "jni.h"
int* wx_GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
{
 return (*env)->GetIntArrayElements(env, array, isCopy);
}

which was exported to GO using

/*
#cgo LDFLAGS: -L${SRCDIR} -lwc

#include "wc.h"
*/

The compilation went fine and go lib libnnturboroute was created but once i try to load the lib from within Scala using System.loadLibrary(library) I get the following exception

An exception or error caused a run to abort: /libnnturboroute.dylib: dlopen(/libnnturboroute.dylib, 1): Library not loaded: libwc.dylib. It appears that from jvm is not able to load libwc.dylib from within the JNI exposed method. I understand that dynamic dependency libraries need to be called from within JNI code . However i can't load library from with golang code since C.dlopen would itself be needed to be imported via C wrapper library .

0

There are 0 best solutions below