如何创建jni.h文件以从Java调用C文件

huangapple go评论58阅读模式
英文:

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&quot;$JAVA_HOME/include&quot; -I&quot;$JAVA_HOME/include/darwin/&quot; -o libjniexample.jnilib -shared JNIExample.c I receive this error:

JNIExample.c:2:10: fatal error: &#39;jni.h&#39; file not found
#include &lt;jni.h&gt;
         ^~~~~~~
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)

huangapple
  • 本文由 发表于 2020年8月12日 00:50:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63362796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定