jni.h: no such file or directory

Leshi Wang picture Leshi Wang · Nov 20, 2012 · Viewed 81.9k times · Source

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!

Answer

Naytzyrhc picture Naytzyrhc · Nov 20, 2012

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"