英文:
'jni.h' file not found
问题
I'm getting this error in my Mac, Java 11.
我在我的 Mac 上遇到了这个错误,使用的是 Java 11。
I've gone through all the similar questions in stack overflow. They suggest to set JAVA_HOME properly. I think I have configured properly and ensured jni.h is present in the directory.
我已经查看了 Stack Overflow 上所有类似的问题。他们建议正确设置 JAVA_HOME。我认为我已经正确配置,并确保 jni.h 存在于目录中。
My environment variables
我的环境变量
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
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
Complete ERROR
完整的错误信息
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.
Still getting the error. I'm not sure what am I missing here.
仍然遇到错误。我不确定我漏掉了什么。
Background:
背景:
I'm trying to use quickjs in java using https://github.com/HarlonWang/quickjs-wrapper. Getting this error while running the command cmake --build ./build/cmake --target quickjs-java-wrapper -j 6
我正在尝试在 Java 中使用 quickjs,使用 https://github.com/HarlonWang/quickjs-wrapper。在运行命令 cmake --build ./build/cmake --target quickjs-java-wrapper -j 6
时出现此错误。
Please note that Nashorn is deprecated. Therefore I didn't use it.
请注意,Nashorn 已被弃用。因此我没有使用它。
英文:
I'm getting this error in my Mac, Java 11.
I've gone through all the similar questions in stack overflow. They suggest to set JAVA_HOME properly. I think I have configured properly and ensured jni.h is present in the directory.
My environment variables
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
Complete ERROR
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.
Still getting the error. I'm not sure what am I missing here.
Background:
I'm trying to use quickjs in java using https://github.com/HarlonWang/quickjs-wrapper. Getting this error while running the command cmake --build ./build/cmake --target quickjs-java-wrapper -j 6
Please note that Nashorn is deprecated. Therefore I didn't use it.
答案1
得分: 2
错误显示您在编辑时未设置JAVA_HOME
环境变量,当您运行cmake
生成构建系统时。
只是为了确保,删除您的构建目录,并再次运行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
英文:
The error in your edit proves that the JAVA_HOME
environment variable was not set when you ran cmake
to generate the build system.
Just to be sure, nuke your build directory and run cmake
again with the environment variable present:
$ 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
</details>
# 答案2
**得分**: 0
请看这个问题和答案,与类似的查询相关。
[如何让jni.h被找到?](https://stackoverflow.com/questions/14529720/how-to-make-jni-h-be-found)。
看起来你需要向`cmake`提供`include`目录。
请参考这个问题和答案,[如何使用CMake正确添加包含目录](https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake)。
<details>
<summary>英文:</summary>
Take a look at this question and answer, to an similar inquiry.
[how to make jni.h be found?](https://stackoverflow.com/questions/14529720/how-to-make-jni-h-be-found).
It appears you need to provide the `include` directory to `cmake`.
See, this question and answer, [How to properly add include directories with CMake](https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论