rJava linker error licuuc with Anaconda & fopenmp error without Anaconda for macOS Sierra 10.12.4

拟墨画扇 提交于 2019-11-27 15:23:28

I provide the solution in two ways: Anaconda and the Brew way. I suggest you to use the Brew solution. In both cases, I have Oracle's JDK installed and if you do this, remember reconfigure Java for R with sudo R CMD javareconf.

Anaconda (solution to the licuuc error)

A similar linker error occurred here. The anaconda path messes things up as

$ R CMD config --ldflags
  -L/Users/osx/anaconda3/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lm -liconv -licuuc -licui18n

so remove a path like below from ~/.bash_profile

export PATH="/Users/osx/anaconda3/bin:$PATH" #Removed to install rJava

so we should get something like

$ R CMD config --ldflags
  -F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv

and after this rJava can be installed even with Anaconda with

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

congratulations!

Brew (solution to fopenmp error)

Your R installation should be done with Homebrew cask such that

brew cask install r-app

where brew's r package is not enough for this. Shortly, the forenmp problem is in the compiler not having the flag so we have to recompile the compiler. This solution is explained more thoroughly here. The problem in the question is for 3.3.* R and gcc solution used such that

#xcode-select --install #if Xcode commandline tools not installed
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!

Solutions here mentioned also in the following because of similar problems

  1. Install rJava on macOS Sierra 10.12.1: linker error licuuc

  2. rJava on MacOS Sierra 10.12.15: unsupported option fopenmp

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