how to make jni.h be found?

后端 未结 11 1186
轻奢々
轻奢々 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:22

    For me it was a simple matter of being sure to include the JDK installation (I'd only had the JRE). My R CMD javareconf output was looking like:

    Java interpreter : /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
    Java version     : 1.8.0_191
    Java home path   : /usr/lib/jvm/java-8-openjdk-amd64/jre
    Java compiler    : not present
    Java headers gen.:
    Java archive tool:
    
    trying to compile and link a JNI program
    detected JNI cpp flags    :
    detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
    gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c conftest.c -o conftest.o
    conftest.c:1:17: fatal error: jni.h: No such file or directory
    compilation terminated.
    /usr/lib/R/etc/Makeconf:159: recipe for target 'conftest.o' failed
    make: *** [conftest.o] Error 1
    Unable to compile a JNI program
    
    
    JAVA_HOME        : /usr/lib/jvm/java-8-openjdk-amd64/jre
    Java library path:
    JNI cpp flags    :
    JNI linker flags :
    Updating Java configuration in /usr/lib/R
    Done.
    

    And indeed there was no include file in my $JAVA_HOME. Very simple remedy:

    sudo apt-get install openjdk-8-jre openjdk-8-jdk
    

    (note that this is specifically intended to install the openJDK and not the one from Oracle)

    Afterwards all is well:

    Java interpreter : /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
    Java version     : 1.8.0_191
    Java home path   : /usr/lib/jvm/java-8-openjdk-amd64/jre
    Java compiler    : /usr/lib/jvm/java-8-openjdk-amd64/jre/../bin/javac
    Java headers gen.: /usr/lib/jvm/java-8-openjdk-amd64/jre/../bin/javah
    Java archive tool: /usr/lib/jvm/java-8-openjdk-amd64/jre/../bin/jar
    
    trying to compile and link a JNI program
    detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
    detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
    gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include -I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include/linux     -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c conftest.c -o conftest.o
    g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR
    
    
    JAVA_HOME        : /usr/lib/jvm/java-8-openjdk-amd64/jre
    Java library path: $(JAVA_HOME)/lib/amd64/server
    JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
    JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
    Updating Java configuration in /usr/lib/R
    Done.
    
    0 讨论(0)
  • 2020-11-30 03:29

    I usually define my JAVA_HOME variable like so:

    export JAVA_HOME=/usr/lib/jvm/java/
    

    Therein are the necessary include files. I sometimes add the below to my .barshrc when I compile a lot of things that need it.

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

    In case you are on Ubuntu:

    #X means 6,7,8...
    apt install openjdk-X-jdk
    
    0 讨论(0)
  • 2020-11-30 03:32

    None of the posted solutions worked for me.

    I had to vi into my Makefile and edit the path so that the path to the include folder and the OS subsystem (in my case, -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux) was correct. This allowed me to run make and make install without issues.

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

    I don't know if this applies in this case, but sometimes the file got deleted for unknown reasons, copying it again into the respective folder should resolve the problem.

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