【发布时间】:2014-10-26 10:03:34
【问题描述】:
这个问题已经被问了好几次,并且有不同的接受答案。但它们都不适合我。
我已经从我的项目中制作了一个 jni dll,以便在 64x windows 7 中使用 eclipse 和 jdk1.7.0_10(64 位)。但在加载我的 DLL 后,我得到 java.lang.UnsatisfiedLinkError.
我开始基于这个guide 创建一个helloworld 项目。我做它所说的一切。但我已经收到此错误:
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;
}
【问题讨论】:
-
出于好奇,因为它可能会帮助您调试问题,如果您尝试使用JavaCPP,它是否有效?
-
@SamuelAudet 我会试试的
标签: java c++ c eclipse java-native-interface