0
votes

I want to get two functions from a dynamic shared object library [developped with C/C++]. To call this DLL from my java application, I have used Java JNI. However, after compiling the Java application I find the compiler has generated a headerfile jni.h. I added the file in my DLL, but when I tried compiling the DLL project, I got the following compilation error:

fatal error: jni.h: No such file or directory #include

I tried to include the header file directories :

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

Without any success

the header file JNIServerLib.h

    /* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jniserver_JNIServer */

#ifndef _Included_jniserver_JNIServer
#define _Included_jniserver_JNIServer
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     jniserver_JNIServer
 * Method:    BZ_receiving
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_jniserver_JNIServer_BZ_receiving
  (JNIEnv *, jobject);

/*
 * Class:     jniserver_JNIServer
 * Method:    BZ_sending
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_jniserver_JNIServer_BZ_sending
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Simple java program JNIServer.java

public class JNIServer {
    public native void BZ_receiving();
    public native void BZ_sending();
    /**
     * @param args the command line arguments
     */

    static{
        System.loadLibrary("JNIServer");
    }

    public static void main(String[] args) {
        new JNIServer().BZ_receiving();
        new JNIServer().BZ_sending();
    }

}
2
You should probably have a look at JNA, and see whether it can simplify your lifefge
Is the JAVA_HOME environment variable declared, and does it point to the correct directory for the JDK?Petesh
it's just a symbol of : C:\Program Files\Java\jdk1.8.0_65\include and C:\Program Files\Java\jdk1.8.0_65\include\win32Oussama
@fge articl this is an artical of methodOussama

2 Answers

0
votes

You cannot have a gap between /I and the filepath. Changing it to

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

should work.

0
votes

Example

The following command looks for the include files requested by MAIN.c in the following order: first in the directory containing MAIN.c, then in the \INCLUDE directory, then in the \MY\INCLUDE directory, and finally in the directories assigned to the INCLUDE environment variable.

CL /I \INCLUDE /I\MY\INCLUDE MAIN.C

Make sure the header file is in one of the Include directories.

Source