31

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!

Leshi Wang
  • 313
  • 1
  • 3
  • 8

1 Answers1

42

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"
AlanFoster
  • 8,156
  • 5
  • 35
  • 52
Naytzyrhc
  • 2,297
  • 26
  • 39
  • 3
    I don't know what it means, how do i add it in codeblocks? and what do you mean /I – Leshi Wang Nov 20 '12 at 05:30
  • 3
    Thanks! 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! thanks – Leshi Wang Nov 20 '12 at 05:38
  • The meaning of above command is: -I Just in case you haven't set up JAVAHOME so you can put the path of directory which contains jni.h file. – Linh Lino May 29 '14 at 17:51
  • 1
    I am using Visual studio community 2013, how can i add JDK path to the include path. I am not an expert so not sure what to do with /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" – GeorgeOfTheRF Sep 16 '15 at 15:39
  • @mrcet007 please check Leshi's comment above, i think it should be still valid. – Naytzyrhc Sep 17 '15 at 01:40
  • 2017 visual studio , just copy the file jni.h to folder at o D:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include – TSG anti SO dark forces Nov 10 '17 at 06:12