15

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.

2 Answers 2

33
+500

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'.

4
  • Any clue where my personal makevars file is? $ cd ~/.R/Makevars -bash: cd: /Users/me/.R/Makevars: No such file or directory
    – BLT
    Jun 30, 2017 at 21:47
  • 3
    There isn't one by default, you need to create the ~/.R/ directory and Makevars file if it doesn't exist.
    – Jim
    Jul 1, 2017 at 22:19
  • R --quiet -e 'install.packages("rJava", type="binary", repos="http://cran.us.r-project.org")' from the command line got it for me. Jul 20, 2017 at 2:20
  • 1
    Version 2. with clang did not work for me. But version 3. did!
    – petzi
    Jun 8, 2018 at 9:36
0

Running following in terminal fixes the package download in RStudio too and you can run the Rjava or r-app without any issues.

    brew cask install r-app 
    brew install homebrew/versions/gcc49 --without-multilib 
    sudo chown -R $(whoami):admin /usr/local
    brew link --overwrite --force gcc49
    brew unlink gcc49 && brew link gcc49
    brew install llvm
    mkdir ~/.R; touch ~/.R/Makevars

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.