I keep getting a java.lang.UnsatisfiedLinkError error every time I run my program. I have a native, a wrapper, and the program to call the native through the wrapper.<
I think the problem is that your JNI signature doesn't match. That is:
JNIEXPORT void JNICALL native_MessageBox(string text, string title);
should be something like:
JNIEXPORT void JNICALL java_com_example_Wrapper_native_MessageBox(string text, string title);
where, java_com_example should be replaced with your package name (. to be replace with _ in package name).
OR
I would suggest you to generate your native function signature and declaration using javah -jni option available in java.
If you test with
nativeFile = new File(filename + ".dll");
if (!nativeFile.exists())
System.exit(1);
you should use it !!
System.load(nativeFile);
There are two different ways to load a native library into a running Java program:
System.loadLibrary(String)
and System.load(String)
.
The System.loadLibrary
method allows us to load a library from the "default" path.
System.loadLibrary("HelloWorld");
System.load
allows us to load a library from anywhere via its absolute path.
System.load("c:/path/to/dll/HelloWorld.dll")
;
Another thing which could be reason for that error is missing header file when you compile our cpp library. Make sure that you included header in your cpp file.