這已被問了幾次,並有不同的接受答案。但他們都沒有爲我工作。
我從我的項目中製作了一個jni dll,用於使用eclipse和jdk1.7.0_10(64位)的64x windows 7。但加載我的DLL後,我得到java.lang.UnsatisfiedLinkError。
我開始創建一個基於這個guide的helloworld項目。我做它所說的一切。但我已經收到此錯誤:JNI:得到java.lang.UnsatisfiedLinkError
Exception in thread "main" java.lang.UnsatisfiedLinkError: test.HelloWorld.print()V
at test.HelloWorld.print(Native Method)
at test.HelloWorld.main(HelloWorld.java:24)
是的,我已經包括在庫路徑和是的,我構建C項目64和是的,我使用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;
}
出於好奇,你的包名稱,因爲它可以幫助您調試問題,如果你用[JavaCPP]嘗試(HTTPS:/ /github.com/bytedeco/javacpp),它工作嗎? – 2014-09-02 07:48:59
@SamuelAudet我會試試 – osyan 2014-09-02 07:52:19