这个问题已经被问过好几次,并且有不同的接受答案。但它们都不适合我。
我从我的项目中制作了一个 jni dll,用于 64x windows 7,使用 eclipse 和 jdk1.7.0_10(64 位)。但是在加载我的 DLL 之后,我得到了 java.lang.UnsatisfiedLinkError。
我开始基于这个创建一个 helloworld 项目 guide .我做了它说的一切。但我已经收到此错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: test.HelloWorld.print()V
at test.HelloWorld.print(Native Method)
at test.HelloWorld.main(HelloWorld.java:24)
是的,我已经包含了库路径,是的,我已经为 x64 构建了 C 项目,是的,我正在使用 64 位 jvm。
代码:
package test;
public class HelloWorld {
public native void print(); //native method
static //static initializer code
{
try{
System.loadLibrary("CLibHelloWorld");
}
catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args)
{
HelloWorld hw = new HelloWorld();
hw.print(); // ==> i get error on this line
}
}
和
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: print
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_print
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
和
#include "HelloWorld.h"
#include "jni.h"
#include "stdio.h"
JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Hello world\n");
return;
}
最佳答案
test.HelloWorld.print
的 C 名称是
Java_test_HelloWorld_print
您缺少 _test
- 您是否使用默认包中的类运行 javah?
关于java - JNI : Get java. lang.UnsatisfiedLinkError 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25618315/