安装 R 包报错 clang: error: unsupported option '-fopenmp' 的解决方法

2020-06-02 15:29:17 浏览数 (1)

MacOS 上安装 R 包

代码语言:javascript复制
install.packages("data.table")

后面提示是否安装需要编译的版本: Do you want to install from sources the package which needs compilation?y/n 选择了 y 之后,报错

代码语言:javascript复制
clang: error: unsupported option '-fopenmp' 

网上找到的解决方法是:

  1. 安装 clang-omp
代码语言:javascript复制
brew install clang-omp

但是提示:

代码语言:javascript复制
Error: No available formula with the name "clang-omp"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
  1. 原来是 clang-omp 迁移到了 llvm 中,遂安装 llvm
代码语言:javascript复制
brew install llvm
ln -s /usr/local/opt/llvm/bin/clang /usr/local/bin/clang-omp
  1. 但是还是同样的报错,观察错误提示:
代码语言:javascript复制
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c assign.c -o assign.o
clang: error: unsupported option '-fopenmp'

发现,执行的是 clang,而不是 clang-omp,所以在命令行执行

代码语言:javascript复制
ln -s /usr/local/opt/llvm/bin/clang /usr/local/bin/clang
ln -s /usr/local/opt/llvm/bin/clang   /usr/local/bin/clang  

只加一个 clang 的软链接,后面会发现还会有个 clang 的报错,因此需要 clang 也要加。

2018.5.23:安装包“ddalpha”出现问题

代码语言:javascript复制
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

最后解决方法:

代码语言:javascript复制
mkdir ~/.R
cd .R
vim Makevars

Makevars里面加上一句:

代码语言:javascript复制
FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`

保存,再重新在 R 中安装:install.packages("ddalpha") 即可。

0 人点赞