rJava链接器错误licuuc与Anaconda&没有Anaconda for macOS Sierra 10.12.4的{fopenmp错误

时间:2017-07-16 17:15:41

标签: r macos homebrew macos-sierra rjava

我想在macOS Sierra 10.12.4上安装rJava。根据{{​​1}},我当前的Java版本为Java version: 1.8.0_131。我已经用Homebrew的cask安装了Java。

我的Java运行以下

R CMD javareconf|grep version

我的R版本是

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

R Java配置运行

R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin11.4.2 (64-bit)

看起来已正确设置为引导here和此SO线程unable to compile JNI program rJava,因此JDK看起来已正确安装。

我使用命令$ R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.8.0_131 Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre Java compiler : /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Non-system Java on macOS trying to compile and link a JNI program detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm During startup - Warning messages: 1: Setting LC_COLLATE failed, using "C" 2: Setting LC_TIME failed, using "C" 3: Setting LC_MESSAGES failed, using "C" 4: Setting LC_MONETARY failed, using "C" clang -I/Volumes/osx/201705_anaconda/anaconda/lib/R/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/Volumes/osx/201705_anaconda/anaconda/include -fPIC -I/Volumes/osx/201705_anaconda/anaconda/include -c conftest.c -o conftest.o clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Volumes/osx/201705_anaconda/anaconda/lib/R/lib -arch x86_64 -L/Volumes/osx/201705_anaconda/anaconda/lib -lgfortran -L/Volumes/osx/201705_anaconda/anaconda -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm -L/Volumes/osx/201705_anaconda/anaconda/lib/R/lib -lR -lintl -liconv -lc -Wl,-framework -Wl,CoreFoundation JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre Java library path: $(JAVA_HOME)/lib/server JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm Updating Java configuration in /Volumes/osx/201705_anaconda/anaconda/lib/R Done.

得到链接器错误
install.packages("rJava")

尽管Java源代码存在同样的错误:官方JDK和Homebrew的Java返回相同的链接器/库错误。

Anaconda可能导致此链接器/库licuuc错误的原因以及如何修复它?

旧帖子

  1. Install rJava on macOS Sierra 10.12.1: linker error licuuc:使用MacPorts的候选解决方案

  2. rJava on MacOS Sierra 10.12.15: unsupported option fopenmp

  3. rJava load error in RStudio/R after "upgrading" to OSX Yosemite

  4. Install xlsx and rJava on macOS Mavericks 10.9.5

  5. 我已尝试修复

    1. checking Java support in R... present: interpreter : '/usr/bin/java' archiver : '/usr/bin/jar' compiler : '/usr/bin/javac' header prep.: '/usr/bin/javah' cpp flags : '-I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin' java libs : '-L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm' ... 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’ here

    2. 的指导下返回NULL options("java.home")
    3. Unbealled Homebrew的Java并将其替换为Oracele的Java和JDK here:同样的licuuc库/链接器错误仍然存​​在。我在this的引导下尝试了options("java.home"="/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/")但错误相同sudo Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'

    4. 从El Capitan 10.11.6更新到Sierra 10.12.4的macOS,但同样的licuuc库/链接器错误仍然存​​在。

    5. 在没有sudo的情况下运行,javac丢失(跟随此here和此here)。通过将javac目录指向licuuc library not found但更好的解决方案,可能最容易解决此错误?当我用sudo运行它时,我得到了相同的licuuc错误。

      /usr/bin/javac
    6. 删除Anaconda R CMD javareconf -e LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_LD_LIBRARY_PATH Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")' Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/javac" (-1) make[2]: *** [org/rosuda/JRI/Rengine.class] Error 2 make[1]: *** [src/JRI.jar] Error 2 make: *** [jri] Error 2 ERROR: compilation failed for package ‘rJava’ 后,引导here,并使用cask安装R,以便conda install anaconda-clean; anaconda-clean --yes; rm -rf ~/anaconda因此收到新错误

      brew cask install r-app; sudo R CMD javareconf; Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'
    7. 在没有Anaconda的情况下,什么可能导致这个错误forenmp以及如何修复它?

1 个答案:

答案 0 :(得分:1)

我以两种方式提供解决方案:Anaconda和Brew方式。我建议你使用Brew解决方案。在这两种情况下,我都安装了Oracle的JDK,如果你这样做,请记住用sudo R CMD javareconf重新配置Java for R。

Anaconda(对licuuc错误的解决方案)

发生类似的链接器错误here。蟒蛇的路径会把事情搞得一团糟

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

因此请从~/.bash_profile

中删除下面的路径
export PATH="/Users/osx/anaconda3/bin:$PATH" #Removed to install rJava

所以我们应该得到像

这样的东西
$ R CMD config --ldflags
  -F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv

此后,即使使用Anaconda

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

恭喜!

Brew(解决fopenmp错误)

你的R安装应该使用Homebrew cask来完成

brew cask install r-app

brew的包装还不够。很快,forenmp问题是编译器没有标志,所以我们必须重新编译编译器。更彻底地解释了这个解决方案here。问题中的问题是3.3。* R和gcc解决方案使用

#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

现在

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

现在rJava正在运作!

由于类似的问题

,下面也提到了解决方案
  1. Install rJava on macOS Sierra 10.12.1: linker error licuuc

  2. rJava on MacOS Sierra 10.12.15: unsupported option fopenmp