我得到以下明确的错误,当我在Java测试JNI:异常线程“main” java.lang.UnsatisfiedLinkError中
Exception in thread "main" java.lang.UnsatisfiedLinkError: Italk2learn.hello()V
at Italk2learn.hello(Native Method)
at Italk2learn.main(Italk2learn.java:10)
有与DLL或路径没有问题,因为我的Java的静态代码一流的作品:
static {
try {
System.loadLibrary("Italk2learn");
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
而且我认为它得到了图书馆罚款。
我使用JVM 32位编译并获取C++头文件(javah)和MinGW32 for C++。在这两种情况下,我都使用Eclipse作为C++和Java。
这是我的代码:
的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;
}
你是如何构建你的DLL的?如果你看看Italk2learn.DLL有多大,它在PATH中? –
我在Eclipse中使用GCC C++编译器。大小是75 KB(包括MinGW和JNI),是的,它在我的windows环境变量的路径。 – tludmetal