英文:
How to make jni.h file for calling a c file from Java
问题
I am trying to follow this tutorial https://gist.github.com/DmitrySoshnikov/8b1599a5197b5469c8cc07025f600fdb for simply calling a c file from Java on mac.
I have successfully build my JNIExample.java and compiled it. I also made the JNIExample.h file as well.
But when I follow the 5th step: gcc -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/darwin/" -o libjniexample.jnilib -shared JNIExample.c
I receive this error:
JNIExample.c:2:10: fatal error: 'jni.h' file not found
#include <jni.h>
^~~~~~~
1 error generated.
Do you know how can I generate this file and solve this error?
My environment is mac and I have these files in my folder:
(base) MacBook-Pro-7:JNI-C++ Home$ ls
JNIExample.c JNIExample.h
JNIExample.class JNIExample.java
英文:
I am trying to follow this tutorial https://gist.github.com/DmitrySoshnikov/8b1599a5197b5469c8cc07025f600fdb for simply calling a c file from Java on mac.
I have successfully build my JNIExample.java and compiled it. I also made the JNIExample.h file as well.
But when I follow the 5th step: gcc -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/darwin/" -o libjniexample.jnilib -shared JNIExample.c
I receive this error:
JNIExample.c:2:10: fatal error: 'jni.h' file not found
#include <jni.h>
^~~~~~~
1 error generated.
Do you know how can I generate this file and solve this error?
My environment is mac and I have this files in my folder:
(base) MacBook-Pro-7:JNI-C++ Home$ ls
JNIExample.c JNIExample.h
JNIExample.class JNIExample.java
答案1
得分: 1
jni.h
位于$JAVA_HOME/include。
但是它也会失败,因为jni.h引用了jni_md.h
来处理与特定机器相关的功能。
因此,您将不得不将$JAVA_HOME/include/(linux|win32)添加到包含路径中。(对于MacOS我不确定)
英文:
jni.h
is in $JAVA_HOME/include.
But it will fail, too, as jni.h references jni_md.h
for machine-dependent features.
So you will have to add $JAVA_HOME/include/(linux|win32) to the include paths. (I'm not sure for MacOS)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论