I get the following explicit error when I test JNI in Java:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Italk2learn.hello()V
at Italk2learn.hello(Native Method)
at Italk2learn.main(Italk2learn.java:10)
There's no problem with the dll or paths because the static code of the my java class works well:
static {
try {
System.loadLibrary("Italk2learn");
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
And I think that it gets the library fine.
I use JVM 32 bits to compile and get the C++ header(javah) and MinGW32 for C++. In both cases I use eclipse for C++ and Java.
This is my code:
Java:
public class Italk2learn {
public native void hello();
public static void main(String[] args) {
System.out.println("Hello World Java!");
try {
new Italk2learn().hello();
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
static {
try {
System.loadLibrary("Italk2learn");
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
}
C++ :
#include <jni.h>
#include <stdio.h>
#include "italk2learn.h"
JNIEXPORT void JNICALL Java_Italk2learn_hello(JNIEnv *, jobject) {
printf("Hello World C++!\n");
#ifdef __cplusplus
printf("__cplusplus is defined\n");
#else
printf("__cplusplus is NOT defined\n");
#endif
return;
}
Italk2learn.DLLhow big is it and is it in your PATH?