问题描述
我试图按照本教程https://gist.github.com/DmitrySoshnikov/8b1599a5197b5469c8cc07025f600fdb的操作,只需在Mac上从Java调用c文件即可。
我已经成功构建了JNIExample.java并对其进行了编译。我也制作了JNIExample.h文件。
但是,当我执行第五步:gcc -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/darwin/" -o libjniexample.jnilib -shared JNIExample.c
时,我收到此错误:
JNIExample.c:2:10: fatal error: 'jni.h' file not found
#include <jni.h>
^~~~~~~
1 error generated.
您知道如何生成此文件并解决此错误吗?
我的环境是mac,我的文件夹中有以下文件:
(base) MacBook-Pro-7:JNI-C++ Home$ ls
JNIExample.c JNIExample.h
JNIExample.class JNIExample.java
解决方法
jni.h
在$ JAVA_HOME / include中。
但是它也会失败,因为jni.h为{em> m achine- d 附加功能引用了jni_md.h
。
因此,您必须将$ JAVA_HOME / include /(linux | win32)添加到包含路径。 (我不确定是MacOS)