前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CMake FindJNI module快速查找jni

CMake FindJNI module快速查找jni

原创
作者头像
望天
发布2020-11-19 21:07:05
1.4K0
发布2020-11-19 21:07:05
举报
文章被收录于专栏:along的开发之旅along的开发之旅

最近在编译skija(JetBrains对skia的Java封装),编译报错:

代码语言:javascript
复制
../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,于是添加

代码语言:javascript
复制
# JNI
find_package(JNI)
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include")

第一步find_package查找失败,只能使用set设置手动添加。

JNI Module常用值:

代码语言:javascript
复制
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"这样查找的。

代码语言:javascript
复制
# 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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档