UnesBeig19
UnesBeig19

Reputation: 37

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 this files in my folder:

(base) MacBook-Pro-7:JNI-C++ Home$ ls
JNIExample.c        JNIExample.h
JNIExample.class    JNIExample.java

Upvotes: 0

Views: 165

Answers (1)

JCWasmx86
JCWasmx86

Reputation: 3583

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)

Upvotes: 1

Related Questions