I am trying to install the rJava package on OS X 10.11.6 with R version 3.4.0:
install.packages("rJava", type = "source")
and I get the following error:
clang -o libjri.jnilib Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o -dynamiclib -framework JavaVM -fopenmp -L/usr/local/lib -F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv
clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
From what I can tell, clang is being used as the compiler, using 'fopenmp' which doesn't appear to be supported by clang. Can anyone see a way around this, potentially forcing a different compiler to be used? (note: I know almost nothing about compilers)
Thanks in advance.
This is caused because R 3.4.0 is compiled by CRAN with llvm-4.0.0 (which supports OpenMP), but Apple's fork (installed by default on macOS) does not support OpenMP. There are three solutions
install.packages(type = "binary")
.~/.R/Makevars
).SHLIB_OPENMP_CFLAGS
and SHLIB_OPENMP_CXXFLAGS
in your ~/.R/Makevars
For 2. you can install the compilers with brew install llvm
or brew install gcc --without-multilib
then you will have to add the compiler path to your ~/.R/Makevars
file.
CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++
# Also potentially CXX11 (for C++11 compiler)
CXX11=/usr/local/opt/llvm/bin/clang++
or for gcc
use (double check gcc executable exists and is correctly named)
CC=/usr/local/bin/gcc-7
CXX=/usr/local/bin/gcc-7
# Also potentially CXX11 (for C++11 compiler)
CXX11=/usr/local/bin/gcc-7
Alternatively you can install a CRAN Provided LLVM 4.0 and set the Makevars
file appropriately.
For 3. you simply need to unset the SHLIB_OPENMP_CFLAGS
SHLIB_OPENMP_CFLAGS=
SHLIB_OPENMP_CXXFLAGS=
For more details see OpenMP support in Writing R Extensions.
Note this error has nothing to do with Java or the rJava package in particular, so ideally the question could be renamed to clang: error: unsupported option '-fopenmp'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With