MAC中Rcpp导致部分包安装不上问题及解决方法

报错信息
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [RcppEigen.so] Error 1
ERROR: compilation failed for package ‘RcppEigen’

g.o.o.gle了很多解决办法,搬运一个有用的过来。英文好的可以直接看原文了。https://thecoatlessprofessor.com/programming/cpp/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error/

另:发现The Coatless Professor这个博客做的真心给力啊,强推。

以下为搬运部分:

前言

Rcpp是R中的C++插件。很多时候,即使安装了Xcode依然会出现问题。具体报错如下,大家根据自己R版本对号入座:

1)R 3.0.0 - 3.3.0
”-lgfortran” Error

ld: warning: directory not found for option
'-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
ld: warning: directory not found for option
'-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see
invocation)

”-lquadmath” Error

ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lquadmath
clang: error: linker command failed with exit code 1 (use -v to see invocation) make: ***
[sourceCpp_93074.so] Error 1 clang++
-I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include"

2)R 3.4.0

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: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see
invocation)

本质上,这两个报错起源于相同的问题。即,MAC OS版本的R是根据gfortran-4.8 (R 3.0.0 - R 3.3.0) 或者 gfortran-6.1 (> = R 3.4.0) 编译的。

最初,the official cran mirror of R tools for OS X and R tools for OS X on r.research.att.com 列举了很多过时的gfortran binary。但是,事实上你需要根据你的R版本来获得正确的gfortran binary。因为R 3.4.0开始用OpenMP,而之前的版本没有用。
因此,对于R 3.0.0 - 3.3.0的用户来说,因为一些文件在指定的文件夹下丢失,你的gfortran会获得 “-lgfortran” error 和 “-lquadmath” error。
而对于R 3.4.0及以后的用户,你需要获得官方gfortran binary

解决办法:

1)R 3.0.0 - 3.3.0
打开optional libraries, frameworks and applications for Mac OS X on r.research.att.com,下载 gfortran-4.8.2-darwin13.tar.bz2文件
打开终端terminal

sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

此后,在你的/usr/bin下,就会多出x86_64-apple-darwin13.0.0-gfortran 这个文件夹,问题解决,撒花~~~

2)R 3.4.0
由于我的R版本是R.3.3.0,所以没有看这部分的教程,所以大家自行去看原文档吧~~

你可能感兴趣的:(MAC中Rcpp导致部分包安装不上问题及解决方法)