rJava on MacOS Sierra 10.12.15: unsupported option fopenmp

别说谁变了你拦得住时间么 提交于 2019-11-30 19:27:20

This article here solved this fopenmp issue for me on macOS Sierra 10.12.4. I outlined the solution here but also below. The problem is that forenmp option is not supported in macOS gcc so we have to compile a new version of the gcc.


Solution to forenmp problem

I have tested this with Homerew's r-app brew cask install r-app and Oracle's JDK. Then I did the following

brew install homebrew/versions/gcc49 --without-multilib #Long ~70min compiling...
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

echo "VER=-4.9 
CC=gcc$(VER)
CXX=g++$(VER)
CXX1X=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/4.9.3/lib/gcc/4.9" > ~/.R/Makevars

and now

sudo R CMD javareconf 
Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'

and now rJava is working!

Comments using OSX 10.12.6 with Java 1.8.0_181 and dealing with the above issue and another issue related to compiling rJava.

First:

Install rJava with these commands:

wget https://cran.r-project.org/src/contrib/rJava_0.9-10.tar.gz
tar xvfz rJava_0.9-10.tar.gz
cd rJava
R CMD INSTALL rJava

Why use R CMD INSTALL? This will keep the config.log file that will allow you to debug things; install.packages() does not and help you get might not be very helpful in that case (e.g. https://github.com/s-u/rJava/issues/111).

Second:

Make sure you run the following, if you've updated Java (remember you need the JDK, not JRE).

sudo R CMD javareconf

Error (checking JNI data types):

To fix this error:

checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.

do this:

sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
sudo ln -f -s /usr/local/lib/libjvm.dylib /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/

Error (unsupported option '-fopenmp):

To fix this error:

clang: error: unsupported option '-fopenmp

do the following:

Note: The instructions may need to be modified for newer versions of gcc, but make sure you get a version greater than 7 (see notes that follow); the following command can be used to find out the available versions:

brew search gcc

Then install gcc:

brew install gcc@7
sudo chown -R $(whoami):admin /usr/local
brew link --overwrite --force gcc@7
brew unlink gcc@7 && brew link gcc@7
brew install llvm
mkdir -p ~/.R

## Check the versions and folder in FLIBS match what you install
echo "CC=gcc-7
CXX=g++-7
CXX1X=g++-7
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc\@7/7.3.0/lib/gcc/7" > ~/.R/Makevars

Notes: You need any version of gcc greater than 7; the without-multilib flag mentioned in the earlier answer may not be available, but it is important. Why the without-multilib flag?: https://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/ and OpenMP/gcc on macOS : gcc --without-multilib not available

Then install rJava

R CMD INSTALL rJava

Finally, test library (you should see your Java version):

library(rJava)
.jinit()
.jcall("java/lang/System", "S", "getProperty", "java.runtime.version")

Take a look here:

http://www.owsiak.org/?p=3671

You can find quite detailed description of how to deal with rJava in macOS.

Make sure to install JDK that is provided by Oracle before you proceed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!