jni 异常:Exception in thread "main" java.lang.UnsatisfiedLinkError: hello
java代码:
public class TestDLL {
static{
System.loadLibrary("goodluck");
}
public native void hello();
public static void main(String[] args){
System.out.println(System.getProperty("java.library.path"));
System.out.println("start");
new TestDLL().hello();
}
}
c头文件 javah生成
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
/* Header for class TestDLL */
#ifndef _Included_TestDLL
#define _Included_TestDLL
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestDLL
* Method: hello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestDLL_hello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
c源文件:
#include "goodluck.h"
#include "stdio.h"
JNIEXPORT void JNICALL Java_TestDLL_hello(JNIEnv * env, jclass jc){
printf("hello\n");
}
执行时,总是报Exception in thread "main" java.lang.UnsatisfiedLinkError: hello
当然dll文件 在当前目录 system32下都放过。