Install rJava on macOS Sierra 10.12.1: linker erro

2019-04-12 16:47发布

问题:

I am trying to install rJava within R-Studio but the error

ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/Users/iMacLinda/Library/R/3.3/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

R

version _ platform x86_64-apple-darwin16.1.0 arch x86_64 os darwin16.1.0 system x86_64, darwin16.1.0 status major 3 minor 3.2 year 2016 month 10 day 31 svn rev 71607 language R version.string R version 3.3.2 (2016-10-31) nickname Sincere Pumpkin Patch

How can I fix this linker error?

回答1:

I have found solution elsewhere with MacPorts, steps 1-5 guided by here and steps 6 guided by here.

  1. As root (sudo bash), edit /opt/local/Library/Frameworks/R.framework/Resources/etc/Makeconf and change the line LIBS = -llzma -lm -liconv -licuuc -licui18n to LIBS = -llzma -lm -liconv

  2. install the original 1.6 Mac Java

  3. run export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

  4. R CMD javareconf

  5. Now you can start R and do install.packages("rJava").

  6. sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib



回答2:

There is a solution for this with Anaconda here. The problem was with the path variable so perhaps this could solve the problem here as well. I outline the solution below about how it could be solved here.


Clean up your path

  1. Check up your config settings

    R CMD config --ldflags
    -L/Users/osx/anaconda3/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lm -liconv -licuuc -licui18n
    
  2. Test this mv ~/.bash_profile ~/.bash_profile_backup.

  3. Restart your terminal.

  4. Now the environment variables in R should be different

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

    sudo R CMD javareconf 
    Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")' 
    
  6. If you was able to install rJava, the problem was in your path otherwise try alternative solutions.

Alternative solution with Homebrew

There is also a solution for this with Homebrew here where R is installed with brew cask install r-app and gcc had to be recompiled without a forenmp flag.