【发布时间】:2016-07-15 21:49:26
【问题描述】:
我想从 [使用 C/C++ 开发的] 动态共享对象库中获取两个函数。为了从我的 java 应用程序中调用这个 DLL,我使用了 Java JNI。但是,在编译 Java 应用程序后,我发现编译器生成了一个头文件 jni.h。我在我的 DLL 中添加了该文件,但是当我尝试编译 DLL 项目时,出现以下编译错误:
致命错误:jni.h:没有这样的文件或目录#include
我试图包含头文件目录:
/I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32"
没有成功
头文件JNIServerLib.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jniserver_JNIServer */
#ifndef _Included_jniserver_JNIServer
#define _Included_jniserver_JNIServer
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: jniserver_JNIServer
* Method: BZ_receiving
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_jniserver_JNIServer_BZ_receiving
(JNIEnv *, jobject);
/*
* Class: jniserver_JNIServer
* Method: BZ_sending
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_jniserver_JNIServer_BZ_sending
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
简单的java程序JNIServer.java
public class JNIServer {
public native void BZ_receiving();
public native void BZ_sending();
/**
* @param args the command line arguments
*/
static{
System.loadLibrary("JNIServer");
}
public static void main(String[] args) {
new JNIServer().BZ_receiving();
new JNIServer().BZ_sending();
}
}
【问题讨论】:
-
你应该看看JNA,看看它是否可以简化你的生活
-
是否声明了
JAVA_HOME环境变量,它是否指向JDK 的正确目录? -
它只是一个符号:C:\Program Files\Java\jdk1.8.0_65\include 和 C:\Program Files\Java\jdk1.8.0_65\include\win32
-
@fge articl 这是一篇文章的方法
标签: java c++ c dll java-native-interface