最近在编译skija(JetBrains对skia的Java封装),编译报错:
../src/DirectContext.cc:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
^~~~~~~
1 error generated.
[5/53] Building CXX object CMakeFiles/skija.dir/src/ColorSpace.cc.o
说没有<jni.h>,我本地没有特殊配置,没有很正常。
找了下报错的脚本"native/CMakeLists.txt", 发现里面没有找JNI module,于是添加
# JNI
find_package(JNI)
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include")
第一步find_package查找失败,只能使用set设置手动添加。
JNI Module常用值:
Result Variables:
JNI_INCLUDE_DIRS = the include dirs to use
JNI_LIBRARIES = the libraries to use
JNI_FOUND = TRUE if JNI headers and libraries were found.
Cache Variables:
JAVA_AWT_LIBRARY = the path to the jawt library
JAVA_JVM_LIBRARY = the path to the jvm library
JAVA_INCLUDE_PATH = the include path to jni.h
JAVA_INCLUDE_PATH2 = the include path to jni_md.h
JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
看FindJNI文档也可发现,其也是借助于JAVA_HOME。
The caller may set variable JAVA_HOME to specify a Java installation prefix explicitly.
查看"Modules/FindJNI.cmake",可见其也是根据哪个文件夹包含"jni.h"这样查找的。
# add in the include path
find_path(JAVA_INCLUDE_PATH jni.h
${JAVA_AWT_INCLUDE_DIRECTORIES}
)
set(JNI_LIBRARIES
${JAVA_AWT_LIBRARY}
${JAVA_JVM_LIBRARY}
)
set(JNI_INCLUDE_DIRS
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2}
${JAVA_AWT_INCLUDE_PATH}
)
find_path (<VAR> name1 [path1 path2 ...])
This command is used to find a directory containing the named file. A cache entry named by<VAR>
is created to store the result of this command. If nothing is found, the result will be<VAR>-NOTFOUND
.
也就是说查找name1所在的目录,存到<VAR>中返回;如果找不到,就存到<VAR>-NOTFOUND
参考:
https://github.com/JetBrains/skija
https://cmake.org/cmake/help/v3.0/module/FindJNI.html
https://cmake.org/cmake/help/latest/module/FindJNI.html
https://cmake.org/cmake/help/latest/command/find_path.html
https://cloud.tencent.com/developer/article/1433739
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。