本文介绍了用于安装R软件包的备用编译器:clang:错误:不支持的选项'-fopenmp'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R版本3.4.0在OS X 10.11.6上安装rJava包:

I am trying to install the rJava package on OS X 10.11.6 with R version 3.4.0:

install.packages("rJava", type = "source")

我收到以下错误:

clang -o libjri.jnilib Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o  -dynamiclib -framework JavaVM -fopenmp -L/usr/local/lib -F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv    
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’

据我所知,clang被用作编译器,使用'fopenmp',而clang似乎不支持它。任何人都可以看到解决这个问题的方法,可能会强制使用不同的编译器吗? (注意:我对编译器几乎一无所知)

From what I can tell, clang is being used as the compiler, using 'fopenmp' which doesn't appear to be supported by clang. Can anyone see a way around this, potentially forcing a different compiler to be used? (note: I know almost nothing about compilers)

提前致谢。

推荐答案

这是因为R 3.4.0是由CRAN编译的llvm-4.0.0(支持OpenMP),但Apple的fork(默认安装在macOS上)支持OpenMP。有三种解决方案

This is caused because R 3.4.0 is compiled by CRAN with llvm-4.0.0 (which supports OpenMP), but Apple's fork (installed by default on macOS) does not support OpenMP. There are three solutions


  1. 使用CRAN提供的包二进制文件,例如 install.packages(type =binary)

  2. 安装支持OpenMP的编译器,例如来自hombrew的gcc或clang ,但是你还必须修改个人makevars文件中的变量(〜/ .R / Makevars )。

  3. 取消设置 SHLIB_OPENMP_CFLAGS SHLIB_OPENMP_CXXFLAGS 在您的〜/ .R / Makevars

  1. Use the package binaries provided by CRAN, e.g. install.packages(type = "binary").
  2. Install a compiler that does support OpenMP, such as gcc or clang from hombrew, however you will also have to modify variables in your personal makevars file (~/.R/Makevars).
  3. Unset SHLIB_OPENMP_CFLAGS and SHLIB_OPENMP_CXXFLAGS in your ~/.R/Makevars

对于2.您可以使用 brew install clang 或<$ c安装编译器$ c> brew install gcc --without-multilib 然后你必须将编译器路径添加到〜/ .R / Makevars 文件中。

For 2. you can install the compilers with brew install clang or brew install gcc --without-multilib then you will have to add the compiler path to your ~/.R/Makevars file.

CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++
# Also potentially CXX11 (for C++11 compiler)
CXX11=/usr/local/opt/llvm/bin/clang++

gcc 使用(仔细检查gcc可执行文件并正确命名)

or for gcc use (double check gcc executable exists and is correctly named)

CC=/usr/local/bin/gcc-7
CXX=/usr/local/bin/gcc-7
# Also potentially CXX11 (for C++11 compiler)
CXX11=/usr/local/bin/gcc-7

您也可以安装并正确设置 Makevars 文件。

Alternatively you can install a CRAN Provided LLVM 4.0 and set the Makevars file appropriately.

对于3.你只需要取消设置 SHLIB_OPENMP_CFLAGS

For 3. you simply need to unset the SHLIB_OPENMP_CFLAGS

SHLIB_OPENMP_CFLAGS=
SHLIB_OPENMP_CXXFLAGS=

有关详细信息,请参阅。

For more details see OpenMP support in Writing R Extensions.

注意这个错误与Java或rJava包没有任何关系,所以理想情况下问题可以重命名为 clang:error:unsupported option'-fopenmp'

Note this error has nothing to do with Java or the rJava package in particular, so ideally the question could be renamed to clang: error: unsupported option '-fopenmp'.

这篇关于用于安装R软件包的备用编译器:clang:错误:不支持的选项'-fopenmp'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:17