I am working on a Linux server RHEL6 and I installed anaconda. I have the following setup
conda-env version : 4.3.13
conda-build version : 2.1.4
python version : 2.7.13.final.0
rpy2 : 2.8.5
I installed rpy2 to use R in python. But with the version of R installed with conda I have issue to installed "rJava".
checking whether Java run-time works... yes
checking whether -Xrs is supported... yes
checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package 'rJava'
With my standalone version of R installed on the same machine I don't have issue, so I know I have the correct version installed.
For my 2 different setup with the same R version (standalone R with R with conda), I have the same Java version
java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
For both setup, the following variables doesn't exit
R_JAVA_LD_LIBRARY_PATH
JAVA_HOME
defined. The PATH are very similar for standalone:
PATH=/opt/ccda/anaconda2/bin:/opt/opennlp/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
while for R installed with conda I have:
PATH=/opt/ccda/anaconda2/envs/py27CCA/bin:/opt/ccda/anaconda2/bin:/opt/ccda/anaconda2/bin:/opt/opennlp/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Here the info during the compilation. For the standalone R version:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm
While for the R version installed with conda:
interpreter : '/usr/lib/jvm/java/jre/bin/java'
archiver : '/usr/lib/jvm/java/jre/../bin/jar'
compiler : '/usr/lib/jvm/java/jre/../bin/javac'
header prep.: '/usr/lib/jvm/java/jre/../bin/javah'
cpp flags : '-I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux'
java libs : '-L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm'
I tried to get the same path using:
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
export R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server
export JAVA_CPPFLAGS="-I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux"
by the way:
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
but after rerunning:
R CMD javareconf
and recompiling I get the same error while the path seems the same now:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm'
so I don't understand what this means "One or more JNI types differ" and what I should in path and flag to have it working.
R CMD javareconf
Java interpreter : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
Java version : 1.8.0_121
Java home path : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64
Java compiler : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/../bin/javac
Java headers gen.: /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/../bin/javah
Java archive tool: /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/../bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux
detected JNI linker flags : -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/opt/ccda/anaconda2/envs/py27CCA/lib/R/include -DNDEBUG -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux -I/opt/ccda/anaconda2/envs/py27CCA/include -fpic -I/opt/ccda/anaconda2/envs/py27CCA/include -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/opt/ccda/anaconda2/envs/py27CCA/lib/R/lib -L/opt/ccda/anaconda2/envs/py27CCA/lib -lgfortran -o conftest.so conftest.o -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm -L/opt/ccda/anaconda2/envs/py27CCA/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64
Java library path: /usr/lib/jvm/java/jre/lib/amd64/server
JNI cpp flags : -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux
JNI linker flags : -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm
Updating Java configuration in /opt/ccda/anaconda2/envs/py27CCA/lib/R
Done.
I am out of idea since I don't really understand the meaning of the error messages. I tried all the suggestion from the various thread related to similar issues.
Edit: using export
LD_LIBRARY_PATH=$JAVA_HOME/lib/amd64:$JAVA_HOME/lib/amd64/server
solve part of the problem (in such case JAVA_HOME is not needed anymore) but i there is too other issue:
-m64 flags is not used in this case (while it is used with the standalone R version)
/usr/bin/ld: cannot find -liconv
but the library exist:
/opt/ccda/anaconda2/envs/py27CCA/lib/libiconv.so
/opt/ccda/anaconda2/envs/py27CCA/lib/libiconv.so.2
/opt/ccda/anaconda2/envs/py27CCA/lib/libiconv.so.2.5.1
/opt/ccda/anaconda2/envs/py27CCA/lib/preloadable_libiconv.so
but may be not in the path used so I need to fix this now.
Make sure to reconfigure your R environment with explicit settings pointing to JDK.
Make sure that JAVA_HOME points to JDK
export JAVA_HOME=your_JDK_installation
Then, reconfigure R and pass all the locations explicitly
sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar \
JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/server \
JAVA_CPPFLAGS="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux"
Then, try to configure rJava outside R
curl https://cran.r-project.org/src/contrib/rJava_0.9-8.tar.gz -o rJava_0.9-8.tar.gz
tar zxf rJava_0.9-8.tar.gz
cd rJava
./configure
if it works, you should be able to install it from sources inside R
install.packages("rJava", type="source")