java 未找到'jni.h'文件

ffscu2ro  于 2023-05-27  发布在  Java
关注(0)|答案(2)|浏览(197)

我在Mac上遇到了这个错误,Java 11。
我已经看过了堆栈溢出中所有类似的问题。建议正确设置JAVA_HOME。我认为我已经正确配置了jni. h,并确保jni. h存在于目录中。
我的环境变量

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/selvakumar/apache-maven-3.5.2/bin:/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home/bin:/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home/include

填写错误

apples-MacBook-Pro:wrapper-java selvakumar$ cmake --build ./build/cmake --target quickjs-java-wrapper -j 6
[1/3] Building CXX object CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o
FAILED: CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCONFIG_BIGNUM -DCONFIG_VERSION=\"2021-03-27\" -Dquickjs_java_wrapper_EXPORTS -I/include -I/include/darwin -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -MD -MT CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o -MF CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o.d -o CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o -c /Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp
/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
[2/3] Building CXX object CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o
FAILED: CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCONFIG_BIGNUM -DCONFIG_VERSION=\"2021-03-27\" -Dquickjs_java_wrapper_EXPORTS -I/include -I/include/darwin -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -MD -MT CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o -MF CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o.d -o CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o -c /Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp
In file included from /Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp:4:
/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.h:15:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

仍然得到错误。我不知道我错过了什么。

**背景:**我正在使用https://github.com/HarlonWang/quickjs-wrapper在java中使用quickjs。运行cmake --build ./build/cmake --target quickjs-java-wrapper -j 6命令时出现此错误

请注意,Nashorn已被弃用。所以我没有使用它。

f2uvfpb9

f2uvfpb91#

编辑中的错误证明在运行cmake生成构建系统时没有设置JAVA_HOME环境变量。为了确保安全,请删除您的构建目录并再次运行cmake *,其中 * 存在环境变量:

$ rm -rf build/cmake
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home
$ cmake -B build/cmake .
$ cmake --build build/cmake --target quickjs-java-wrapper -j 6
cx6n0qe3

cx6n0qe32#

看看这个问题和答案,一个类似的调查。
how to make jni.h be found?
您似乎需要向cmake提供include目录。
看这个问题和答案How to properly add include directories with CMake

相关问题