Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jni.h: no such file or directory

I'm using Code::Blocks in windows.

I created a dll project trying to get some JNI practice.

In my .h file generated by javah, there's #include jni.h, but when I try to compile it, it keeps saying jni.h: no such file or directory.

I think it has something to do with classpath, but I don't know what it is! It's probably setting that I have to change in Code::Blocks

Could someone please help me to fix it? many thanks

/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class Vector3D */  #ifndef _Included_Vector3D #define _Included_Vector3D #ifdef __cplusplus extern "C" { #endif /*  * Class:     Vector3D  * Method:    magnitude  * Signature: ()D  */ JNIEXPORT jdouble JNICALL Java_Vector3D_magnitude   (JNIEnv *, jobject);  /*   * Class:     Vector3D  * Method:    mult  * Signature: (LVector3D;I)LVector3D;  */ JNIEXPORT jobject JNICALL Java_Vector3D_mult   (JNIEnv *, jobject, jobject, jint);  /*  * Class:     Vector3D  * Method:    equals  * Signature: (LVector3D;)Z  */ JNIEXPORT jboolean JNICALL Java_Vector3D_equals   (JNIEnv *, jobject, jobject);  /*  * Class:     Vector3D  * Method:    dotProduct  * Signature: (LVector3D;LVector3D;)D  */ JNIEXPORT jdouble JNICALL Java_Vector3D_dotProduct   (JNIEnv *, jclass, jobject, jobject);  /*  * Class:     Vector3D  * Method:    makeNormalized  * Signature: (LVector3D;)LVector3D;  */ JNIEXPORT jobject JNICALL Java_Vector3D_makeNormalized   (JNIEnv *, jclass, jobject);  /*  * Class:     Vector3D  * Method:    crossProduct  * Signature: (LVector3D;LVector3D;)LVector3D;  */ JNIEXPORT jobject JNICALL Java_Vector3D_crossProduct   (JNIEnv *, jclass, jobject, jobject);  #ifdef __cplusplus } #endif #endif 

EDIT:
So I did Settings-->Compiler and debugger-->Search directories-->and added "$(JAVA_HOME)\include" and "$(JAVA_HOME)\include\win32" under Compiler, and it was able to find it!

like image 334
Leshi Wang Avatar asked Nov 20 '12 04:11

Leshi Wang


People also ask

Where can I find JNI H?

The JNI header " jni. h " provided by JDK is available under the " <JAVA_HOME>\include " and " <JAVA_HOME>\include\win32 " (for Windows) or " <JAVA_HOME>\include\linux " (for Ubuntu) [Check Mac OS X] directories, where <JAVA_HOME> is your JDK installed directory (e.g., " c:\program files\java\jdk10. 0.

What is JNI h file?

JNI Components h is a C/C++ header file included with the JDK that maps Java types to their native counterparts. javah automatically includes this file in the application header files. JNI data type mapping in variables. Code: boolean jboolean.


1 Answers

You have to add the JDK path to the include path, so the compiler knows the location of the file.

Windows:

/I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" 

Linux:

-I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" 

Mac:

-I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/darwin" 
like image 193
Naytzyrhc Avatar answered Sep 18 '22 17:09

Naytzyrhc