how to make jni.h be found?

后端 未结 11 1200
轻奢々
轻奢々 2020-11-30 03:10

In Ubuntu 12.04, I have jdk7 from sun/oracle installed. When locate jni.h, it prints multiple locations

/usr/lib/jvm/java-6-openjdk-amd64/inclu         


        
相关标签:
11条回答
  • 2020-11-30 03:13

    You have to tell your compiler where is the include directory. Something like this:

    gcc -I/usr/lib/jvm/jdk1.7.0_07/include
    

    But it depends on your makefile.

    0 讨论(0)
  • 2020-11-30 03:14

    Setting JAVA_INCLUDE_DIR to where jni.h is located should solve your problem (setting CPPFLAGS did not work for me)

    Assuming it is /usr/lib64/java/include;

    export JAVA_INCLUDE_DIR=/usr/lib64/java/include
    
    0 讨论(0)
  • 2020-11-30 03:15

    Above answers give you a hardcoded path solution. This is bad on so many levels (java version change, OS change, etc).

    Cleaner solution is to add:

    JAVA_HOME = $(shell dirname $$(readlink -f $$(which java))|sed 's^jre/bin^^')
    

    near the top of your makefile, then add:

    -I$(JAVA_HOME)/include
    

    To your include flags.

    I am posting this because I ran into the same problem and spent too much time googling for wrong answers (I am building an app on multiple platforms so the build environment needs to be transportable).

    0 讨论(0)
  • 2020-11-30 03:17

    Installing the OpenJDK Development Kit (JDK) should fix your problem.

    sudo apt-get install openjdk-X-jdk
    

    This should make you able to compile without problems.

    0 讨论(0)
  • 2020-11-30 03:19

    It needs both jni.h and jni_md.h files, Try this

    gcc -I/usr/lib/jvm/jdk1.7.0_07/include \
      -I/usr/lib/jvm/jdk1.7.0_07/include/linux filename.c
    

    This will include both the broad JNI files and the ones necessary for linux

    0 讨论(0)
  • 2020-11-30 03:22

    Use the following code:

    make -I/usr/lib/jvm/jdk*/include
    

    where jdk* is the directory name of your jdk installation (e.g. jdk1.7.0).

    And there wouldn't be a system-wide solution since the directory name would be different with different builds of JDK downloaded and installed. If you desire an automated solution, please include all commands in a single script and run the said script in Terminal.

    0 讨论(0)
提交回复
热议问题