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

MacOS 上安装 R 包

install.packages("data.table")

后面提示是否安装需要编译的版本:

Do you want to install from sources the package which needs compilation?y/n

选择了 y 之后,报错

clang: error: unsupported option '-fopenmp'

网上找到的解决方法是:

  1. 安装 clang-omp
brew install clang-omp

但是提示:

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
brew install llvm
ln -s /usr/local/opt/llvm/bin/clang /usr/local/bin/clang-omp
  1. 但是还是同样的报错,观察错误提示:
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,所以在命令行执行

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”出现问题

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)

最后解决方法:

mkdir ~/.R
cd .R
vim Makevars

Makevars里面加上一句:

FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`

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

上一篇:json,json对象以及js对象字面量的区别


下一篇:iOS 设计 用户为王 - 关于征询授权、注册及加载等待的体验优化