I have a Go method that returns 2 byte arrays and 2 strings defined as:
// export GetDetails
func GetDetails() (unsafe.Pointer, unsafe.Pointer, *C.char, *C.char) {
...
return C.CBytes(arr1), C.CBytes(arr2), C.CString(str1), C.CString(error)
}
I compile it into libmydetails.so
and call this using Java code defined as:
public class MyLib {
static {
try {
System.loadLibrary("mydetails");
} catch (Exception e) {
...
}
}
public native GoResult GetDetails();
}
public class GoResult extends Structure implements Structure.ByValue {
public GoResult() {
}
public Pointer p1;
public Pointer p2;
public String str;
public String error;
protected List<String> getFieldOrder() {
return Arrays.asList("p1", "p2", "str", "error");
}
}
This is called by an action class as:
public class Action {
MyLib INSTANCE = new MyLib();
GoResult result = INSTANCE.GetDetails();
}
On executing this, libmydetails.so
is successfully loaded, but I get this error while triggering the native method: java.lang.UnsatisfiedLinkError: '<pkg>.GoResult <pkg>.MyLib.GetDetails()
. It looks like it's not able to map GoResult
to (unsafe.Pointer, unsafe.Pointer, *C.char, *C.char)
but I'm not sure what would be the best way to fix it.
When I try loading the library using Library interface instead:
public interface MyLib extends Library {
MyLib INSTANCE = Native.load("mydetails", MyLib.class);
GoResult GetDetails();
}
I'm able to run GetDetails()
locally but my service requires the library to be loaded at Runtime so only System.loadLibrary("mydetails")
works while running it through the service.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744724553a4590103.html
评论列表(0条)