rocker-org / rocker-versioned

Run current & prior versions of R using docker
https://hub.docker.com/r/rocker/r-ver
GNU General Public License v2.0
297 stars 169 forks source link

rJava newly failing to install #11

Closed jsonbecker closed 7 years ago

jsonbecker commented 7 years ago

As recently as Thursday evening, I was able to pull from rocker/rstudio:3.3.1 and install RJDBC and rJava with the Dockerfile below. I have tried all kinds of changes but keep running into similar errors since then. I'd love some help to get back to a working configuration. I am having a heck of a time trying to figure out what changed over night.

FROM rocker/rstudio:3.3.1

RUN apt-get update -qq && apt-get -y --no-install-recommends install \
  libxml2-dev \
  libcairo2-dev \
  libsqlite-dev \
  libmariadbd-dev \
  libmariadb-client-lgpl-dev \
  libpq-dev \
  default-jdk \
  && R CMD javareconf \
  && . /etc/environment \
  && install2.r --error \
    --repos 'http://www.bioconductor.org/packages/release/bioc' \
    --repos $MRAN \ 
    --deps "TRUE" \
    ## explicitly include dplyr & ggplot2 to get their suggests lists
    tidyverse devtools profvis openxlsx RJDBC data.table yaml ggplot2
gcc -std=gnu99 -c -o rjava.o rjava.c -g -Iinclude  -DRIF_HAS_CSTACK -DRIF_HAS_RSIGHAND -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -I/usr/lib/jvm/java-7-openjdk-amd64/jre/../include  -fpic -I/usr/lib/jvm/java-7-openjdk-amd64/jre/../include
rjava.c: In function ‘RJava_request_lock’:
rjava.c:22:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(ipcout, buf, sizeof(ptrlong));
   ^
rjava.c: In function ‘RJava_clear_lock’:
rjava.c:30:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(ipcout, buf, sizeof(ptrlong));
   ^
rjava.c: In function ‘RJava_request_callback’:
rjava.c:39:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(ipcout, buf, sizeof(ptrlong) * 3);
   ^
rjava.c: In function ‘RJava_init_ctrl’:
rjava.c:51:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(ipcout, buf, sizeof(ptrlong));
   ^
rjava.c:52:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
   read(resin, buf, sizeof(ptrlong) * 2);
   ^
gcc -std=gnu99 -o libjri.so Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o  -shared -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm -Wl,--export-dynamic -fopenmp  -L/usr/local/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n
/usr/bin/ld: cannot find -lbz2
/usr/bin/ld: cannot find -licuuc
/usr/bin/ld: cannot find -licui18n
collect2: error: ld returned 1 exit status
make[2]: *** [libjri.so] Error 1
Makefile.all:38: recipe for target 'libjri.so' failed
make[2]: Leaving directory '/tmp/Rtmpni7i3j/R.INSTALLb4526d83498/rJava/jri/src'
Makefile.all:21: recipe for target 'src/JRI.jar' failed
make[1]: *** [src/JRI.jar] Error 2
make[1]: Leaving directory '/tmp/Rtmpni7i3j/R.INSTALLb4526d83498/rJava/jri'
Makevars:14: recipe for target 'jri' failed
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/usr/local/lib/R/site-library/rJava’
Error in install.packages(pkgs = f, lib = lib, repos = if (isMatchingFile(f)) NULL else rep,  :
  installation of package ‘rJava’ had non-zero exit status
In addition: Warning messages:
1: In if (opt$repos == "NULL") { :
  the condition has length > 1 and only the first element will be used
2: In if (opt$repos == "getOption") { :
  the condition has length > 1 and only the first element will be used
cboettig commented 7 years ago

Sorry, Add libicu-dev and libbz2-dev to your apt-get install list. (These were in base r-ver but I pulled out the dev versions to keep that image a bit lighter... Still tweaking r-ver stack a bit, but will tag a release soon & stop fiddling...)

jsonbecker commented 7 years ago

Thanks trying that now and will report back. Once I can get something minimal running, I may just create and open source a container based on r-ver myself that adds rJava and open source that. Seems like it could be useful and likely drags along or requires some dependencies you might not want in r-ver.

jsonbecker commented 7 years ago

That didn't quite do it. Do you know of a place that lists the Linux build dependencies for rJava? All of my Googling has failed me since the recommendation is to install from apt-get which won't work since we're compiling a specific R version.

jsonbecker commented 7 years ago

I think I got it... it was also missing liblzma-dev. Builds take about a half hour, sorry for the notifications/emails but I'll thumbs up this if I confirm that this works and close.

eddelbuettel commented 7 years ago

i) liblzma-dev is a dependency of r-base-dev. If you don't install that ...

ii) Build-time dependencies are recorded and accessible: apt-get build-dep r-cran-rjava

jsonbecker commented 7 years ago

It was liblzma-dev.

i) Because it's listed in BUILDDEPS here, it's removed for images based on r-ver.

ii) Solid. That'll help me make my rJava container. Thanks.

robchallen commented 6 years ago

I also got /usr/bin/ld: cannot find -lz

which I managed to fix with the following: sudo ln -s /usr/lib/libzip.so.2.1.0 /usr/lib/libz.so

eddelbuettel commented 6 years ago

In general: don't do that. libz comes from the zlib package, libzip comes from libzip4.

robchallen commented 6 years ago

OK. Thanks for clearing that up. What should I have done?

eddelbuettel commented 6 years ago

To a first appromixation (and I answered this a few times on the list and on SO):

I thought I could quickly find a good SO answer but failed, sorry. Maybe some googleing will get you there.

robchallen commented 6 years ago

Thanks, I couldn't find the reference to the package on google either, but your recommendation for zlib1g-dev did fix the "cannot find -lz" and rJava does now install.

sudo apt-get install zlib1g-dev

thengl commented 6 years ago

I am also having problems with installing rJava due to the /usr/bin/ld: cannot find -lomp message. Here are my session info details:

> devtools::session_info()
Session info ------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.0 (2018-04-23)
 system   x86_64, linux-gnu           
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       Europe/Berlin               
 date     2018-10-08                  

Packages ----------------------------------------------------------------------
 package       * version date       source        
 base          * 3.5.0   2018-05-24 local         
 compiler        3.5.0   2018-05-24 local         
 datasets      * 3.5.0   2018-05-24 local         
 devtools        1.13.6  2018-06-27 CRAN (R 3.5.0)
 digest          0.6.17  2018-09-12 CRAN (R 3.5.0)
 graphics      * 3.5.0   2018-05-24 local         
 grDevices     * 3.5.0   2018-05-24 local         
 memoise         1.1.0   2017-04-21 CRAN (R 3.5.0)
 methods       * 3.5.0   2018-05-24 local         
 RevoUtils     * 11.0.0  2018-06-04 local         
 RevoUtilsMath * 11.0.0  2018-06-01 local         
 stats         * 3.5.0   2018-05-24 local         
 tools           3.5.0   2018-05-24 local         
 utils         * 3.5.0   2018-05-24 local         
 withr           2.1.2   2018-03-15 CRAN (R 3.5.0)

This is the the result of the R CMD javareconf:

Java interpreter : /usr/bin/java
Java version     : 1.8.0_181
Java home path   : /usr/lib/jvm/java-8-oracle/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/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
clang -I/opt/microsoft/ropen/3.5.0/lib64/R/include -DNDEBUG -I/usr/lib/jvm/java-8-oracle/jre/../include -I/usr/lib/jvm/java-8-oracle/jre/../include/linux -DU_STATIC_IMPLEMENTATION   -g -O2 -fpic  -DU_STATIC_IMPLEMENTATION -O2 -g  -c conftest.c -o conftest.o
clang -shared -L/opt/microsoft/ropen/3.5.0/lib64/R/lib -o conftest.so conftest.o -L/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server -ljvm -L/opt/microsoft/ropen/3.5.0/lib64/R/lib -lR

JAVA_HOME        : /usr/lib/jvm/java-8-oracle/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 /opt/microsoft/ropen/3.5.0/lib64/R
Done.

I've tried installing all additional libraries but no luck. I keep getting:

clang -o libjri.so Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o  -shared -L/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server -ljvm -Wl,--export-dynamic -fopenmp  -L/opt/microsoft/ropen/3.5.0/lib64/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -licui18n -licuuc -licudata -lstdc++ -licuuc -licui18n
/usr/bin/ld: cannot find -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile.all:35: recipe for target 'libjri.so' failed
make[2]: *** [libjri.so] Error 1
make[2]: Leaving directory '/data/RTMP/RtmpJ9Kieb/R.INSTALL939279164ba2/rJava/jri/src'
Makefile.all:19: recipe for target 'src/JRI.jar' failed
make[1]: *** [src/JRI.jar] Error 2
make[1]: Leaving directory '/data/RTMP/RtmpJ9Kieb/R.INSTALL939279164ba2/rJava/jri'
Makevars:14: recipe for target 'jri' failed
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/opt/microsoft/ropen/3.5.0/lib64/R/library/rJava’

thank you

cboettig commented 6 years ago

@thengl Thanks for the report. What image are you using? In rocker/verse, install.packages("rJava") is working fine for me, e.g.

docker run --rm -ti rocker/verse R -e "install.packages('rJava')"

On other images you may need to first install some of the dependencies. See https://www.rocker-project.org/images/ or the README for an overview of the different images.

seohyunjun commented 4 years ago

Thank you it works

i) liblzma-dev is a dependency of r-base-dev. If you don't install that ...

ii) Build-time dependencies are recorded and accessible: apt-get build-dep r-cran-rjava