MacOS Sierra 10.12.15上的rJava:不支持的选项fopenmp

时间:2017-06-06 07:19:06

标签: macos installation macos-sierra rjava

我正在尝试在MacOS Sierra上安装rJava。必须尝试其他其他版本MacOS的提示和指南,例如https://github.com/snowflakedb/dplyr-snowflakedb/wiki/Configuring-R-rJava-RJDBC-on-Mac-OS-X  和Install xlsx and rJava on Mac

但它没有成功。非常感谢任何帮助。感谢。

我的Mac版:macOS Sierra,版本10.12.15 我的R版本:3.4.0(2017-04-21) 我的Rstudio版本:版本0.99.903

Java版:

bash-3.2$ /usr/libexec/java_home -V
bash-3.2$ 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)


bash-3.2$ 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
clang -I/Library/Frameworks/R.framework/Resources/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/usr/local/include   -fPIC  -Wall -g -O2  -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -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 /Library/Frameworks/R.framework/Resources
override rw-r--r--  root/admin for /Library/Frameworks/R.framework/Resources/etc/Makeconf? (y/n [n]) n
not overwritten
override rw-r--r--  root/admin for /Library/Frameworks/R.framework/Resources/etc/ldpaths? (y/n [n]) n
not overwritten
Done.

当我尝试安装rJava时,我跑了

`R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")` 

我收到了错误:

clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’

The downloaded source packages are in
    ‘/private/var/folders/w8/ksbj8dh15bz2lkss7h2tpzk80000gn/T/Rtmp6r9HI0/downloaded_packages’
Warning message:
In install.packages("rJava", type = "source", repos = "http://cran.us.r-project.org") :
  installation of package ‘rJava’ had non-zero exit status

我跑了:

"curl -#ROL https://www.rforge.net/rJava/snapshot/rJava_0.9-8.tar.gz
R CMD INSTALL rJava_0.9-8.tar.gz"

并收到以下错误消息:

clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’

* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava’

我不知道该怎么做。谢谢你的帮助。

3 个答案:

答案 0 :(得分:3)

本文here在macOS Sierra 10.12.4上为我解决了这个fopenmp问题。我概述了解决方案here,但也在下面。问题是macOS gcc不支持forenmp选项,所以我们必须编译新版本的gcc。

解决前庭问题

我已经使用Homerew的r-app brew cask install r-app和Oracle的JDK进行了测试。然后我做了以下

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 :(得分:1)

使用OSX 10.12.6和Java 1.8.0_181进行注释,处理上述问题以及与编译rJava有关的另一个问题。

第一:

使用以下命令安装rJava:

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

为什么要使用R CMD INSTALL?这将保留config.log文件,使您可以调试内容。 install.packages()不能,并且在这种情况下对您的帮助可能不是很有用(例如https://github.com/s-u/rJava/issues/111)。

第二:

如果您已更新Java,请确保运行以下命令(请记住,您需要JDK,而不是JRE)。

sudo R CMD javareconf

错误(正在检查JNI数据类型):

要纠正此错误:

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.

执行此操作:

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/

错误(不支持的选项'-fopenmp):

要纠正此错误:

clang: error: unsupported option '-fopenmp

执行以下操作:

注意:对于较新版本的gcc,可能需要修改说明,但是请确保您获得的版本大于7(请参阅以下说明);以下命令可用于查找可用版本:

brew search gcc

然后安装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

注意:您需要任何大于7的gcc版本。前面的答案中提到的without-multilib标志可能不可用,但这很重要。为什么不使用multilib标志?:https://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/OpenMP/gcc on macOS : gcc --without-multilib not available

然后安装rJava

R CMD INSTALL rJava

最后,测试库(您应该看到Java版本):

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

答案 2 :(得分:0)

看看这里:

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

您可以在macOS中找到有关如何处理rJava的详细说明。

确保在继续之前安装Oracle提供的JDK。