As per much of the advice on SE about getting Mac OS Sierra 10.12.4 to play with rJava nicely, the advice suggests installing from source.
However, when I try and run install.packages("rJava", type = "source") I get an output like so:
> install.packages("rJava", type = "source") trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-8.tar.gz' Content type 'application/x-gzip' length 656615 bytes (641 KB) ================================================== downloaded 641 KB * installing *source* package ‘rJava’ ... ** package ‘rJava’ successfully unpacked and MD5 sums checked checking for gcc... /usr/local/opt/llvm/bin/clang -fopenmp checking whether the C compiler works... no configure: error: in `/private/var/folders/lj/4s8lnxmj4_q8h65zk705k6dr0000gn/T/Rtmp4BrRQs/R.INSTALLd1278e3aab0/rJava': configure: error: C compiler cannot create executables See `config.log' for more details ERROR: configuration failed for package ‘rJava’ * removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava’ Warning in install.packages : installation of package ‘rJava’ had non-zero exit status The downloaded source packages are in ‘/private/var/folders/lj/4s8lnxmj4_q8h65zk705k6dr0000gn/T/RtmpFhnj89/downloaded_packages’ I've tried updating gcc and gfortran using brew, and also modified my makeconf as specified in answers here and have install xcode.
Update: I believe I have openmp installed via clang, which installed via llvm.
Upate 2: as per hrbrmstrs comment, his file at ~/.R/Makevars differed significantly from mine. Mine was I assume a default:
CC=/usr/local/opt/llvm/bin/clang -fopenmp CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include And theirs was:
# shell sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib # ~/.R/Makevars F77 = /usr/local/gfortran/bin/gfortran FC = /usr/local/gfortran/bin/gfortran FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm CC=ccache /usr/local/opt/gcc/bin/gcc-6 -Wunused-argument CXX=ccache /usr/local/opt/gcc/bin/g++-6 -Wunused-argument CXX1X=ccache /usr/local/opt/gcc/bin/g++-6 SHLIB_CXXLD=ccache /usr/local/opt/gcc/bin/g++-6 CCACHE_CPP=yes CCACHE_CPP2=yes MAKE=make -j8 Available as a gist too
Output of install.packages("rJava, type = "source") is now
> install.packages("rJava", type = "source") trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-8.tar.gz' Content type 'application/x-gzip' length 656615 bytes (641 KB) ================================================== downloaded 641 KB * installing *source* package ‘rJava’ ... ** package ‘rJava’ successfully unpacked and MD5 sums checked /Users/davidparr/.R/Makevars:10: *** missing separator. Stop. /Users/davidparr/.R/Makevars:10: *** missing separator. Stop. checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for ANSI C header files... yes checking for sys/wait.h that is POSIX.1 compatible... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for string.h... (cached) yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking whether time.h and sys/time.h may both be included... yes configure: checking whether gcc supports static inline... yes checking whether setjmp.h is POSIX.1 compatible... yes checking whether sigsetjmp is declared... yes checking whether siglongjmp is declared... yes checking Java support in R... /Users/davidparr/.R/Makevars:10: *** missing separator. Stop. configure: error: absent R was configured without Java support. Please run R CMD javareconf as root to add Java support to R. If you do not have root privileges, run R CMD javareconf -e to set all Java-related variables and then install rJava. ERROR: configuration failed for package ‘rJava’ * removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava’ Warning in install.packages : installation of package ‘rJava’ had non-zero exit status The downloaded source packages are in ‘/private/var/folders/lj/4s8lnxmj4_q8h65zk705k6dr0000gn/T/Rtmp7beCd4/downloaded_packages’ Now, when I try to run R CMD javareconf -e as suggested (I am not in root user), I get the following in the terminal.
trying to compile and link a JNI program detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm ccache /usr/local/opt/gcc/bin/gcc-6 -Wunused-argument -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c conftest.c -o conftest.o make: ccache: No such file or directory make: *** [conftest.o] Error 1 Unable to compile a JNI program I definately have a file gcc-6 in the location specified. Why is the line CXX=ccache /usr/local/opt/gcc/bin/g++-6 -Wunused-argument not CXX=/usr/local/opt/gcc/bin/g++-6?
Running sudo R CMD javareconf with and without -e is more optimistic, though I still don't understand the significance of -e:
Java interpreter : /usr/bin/java Java version : 1.8.0_131 Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre Java compiler : /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Non-system Java on macOS trying to compile and link a JNI program detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm /usr/local/opt/gcc/bin/gcc-6 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c conftest.c -o conftest.o /usr/local/opt/gcc/bin/gcc-6 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre Java library path: $(JAVA_HOME)/lib/server JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm Updating Java configuration in /Library/Frameworks/R.framework/Resources Done.
checking for gcc... /usr/local/opt/llvm/bin/clang -fopenmp-- do you have OpenMP installed on your system? If not, that's probably why this is failing.~/.R/MakevarsI use as well as the required symlink to get rJava to work. gist.github.com/hrbrmstr/6f228eead691e72bd0272a25319ea9ee (I usually do theR CMD javareconffirst before installingrJava). There's a long-winded (and I've got no time) as to why the g[++] toolchain is needed vs clang and I think I've seen folks get it to work with clang but I'm g[++] is working fine for me.