jni.h:没有这样的文件或目录Netbeans IDE

fatal error: jni.h: No such file or directory Netbeans IDE

本文关键字:文件 IDE Netbeans jni      更新时间:2023-10-16

我想学习如何从c++调用java函数,经过一些链接后,我知道我们需要在c++文件中添加以下头文件

#include <jni.h>

但是当我在Netbeans IDE中的c++文件中添加此文件时,我得到了以下错误

fatal error: jni.h: No such file or directory

如何删除这个错误,我只是初学者在JNI。

我浏览了之前在stackoverflow上问过的问题,但没能浏览这个问题。

下面是我的编译输出:

"/C/MinGW/MSYS/1.0/bin./make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Simer/Documents/NetBeansProjects/JniDemo'
"/C/MinGW/MSYS/1.0/bin./make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/jnidemo.exe
make.exe[2]: Entering directory `/c/Users/Simer/Documents/NetBeansProjects/JniDemo'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
main.cpp:9:17: fatal error: jni.h: No such file or directory
 #include <jni.h>
                 ^
compilation terminated.
make.exe[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make.exe[2]: Leaving directory `/c/Users/Simer/Documents/NetBeansProjects/JniDemo'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Simer/Documents/NetBeansProjects/JniDemo'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)

你正在编译没有包含Java头文件的MinGW,这就是为什么它抱怨没有找到

尝试将此选项添加到编译命令-I"c:/path/to/jdk/include" -I"c:/path/to/jdk/include/win32" -D__int64="long long"中。

最后一个选项是为了避免由于windows编译器使用__int64类型而gcc使用long long而导致的错误。

你看过Netbeans JNI教程吗?

它非常详细地介绍了你应该做的所有事情。