I was trying to use a .NET DLL from Java code, the tsMemberFunctions.DLL is loaded successfully, but the code fails to call the actual function.
See the snippet below:
public class tsMemberFunctions {
public native void GetMemberJSONSample();
static {
System.loadLibrary("tsMemberFunctions");
System.out.println("Loaded");
}
public static void main(String[] args) {
new tsMemberFunctions().GetMemberJSONSample();
}
}
On executing above method I am getting below error:
Loaded
Exception in thread "main" java.lang.UnsatisfiedLinkError: tsMemberFunctions.GetMemberJSONSample()V
at tsMemberFunctions.GetMemberJSONSample(Native Method)
at tsMemberFunctions.main(tsMemberFunctions.java:12)
Can someone please tell me if I missed anything or anything is incorrect in the code or suggest better alternative for this use case. TIA.
You have to be very careful with the names and exports.
Let's say you have this super simple lib
You have to make sure to build your
DLLfor proper architecture (it will depend on Java version you have - 32/64 bit).Let's say you have
x64 DLLandx64 JDK, you can call your lib like thisIn your case, I bet you don't have
extern "C"in your code - this is why your symbol can't be found by JVM.When it comes to tools, I suggest Visual Studio 2019 (when it comes to creating DLL) and IntelliJ for Java code.
You can find lots of samples here: http://jnicookbook.owsiak.org/ and here: https://github.com/mkowsiak/jnicookbook