Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternate Compiler for Installing R Packages: clang: error: unsupported option '-fopenmp'

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.

like image 292
Jeff Coughlin Avatar asked Apr 24 '17 18:04

Jeff Coughlin


1 Answers

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

  1. Use the package binaries provided by CRAN, e.g. install.packages(type = "binary").
  2. Install a compiler that does support OpenMP, such as gcc or clang from hombrew, however you will also have to modify variables in your personal makevars file (~/.R/Makevars).
  3. Unset 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'.

like image 87
Jim Avatar answered Oct 11 '22 13:10

Jim