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

后端 未结 1 533
终归单人心
终归单人心 2020-12-03 20:44

I want to install rJava on macOS Sierra 10.12.4. My current Java version is Java version: 1.8.0_131, according to R CMD javareconf|grep version. I

相关标签:
1条回答
  • 2020-12-03 21:08

    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

    0 讨论(0)
提交回复
热议问题