使用RcppArmadillo和R 3.1.3以及Mac Yosemite编译错误

Compile error with RcppArmadillo and R 3.1.3 and Mac Yosemite

本文关键字:Mac Yosemite 编译 错误 以及 RcppArmadillo 使用      更新时间:2023-10-16

我最近安装了R 3.1.3。我使用的是Yosemite系统的Mac,我的Xcode是6.2版本。

在我使用sourceCpp("try.CPP")获取CPP文件的源代码后,我得到以下错误。我的try.cpp文件有

#include <RcppArmadillo.h>
#include <math.h>

R 中的错误如下

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_15736.so] Error 1
clang++ -arch x86_64 -ftemplate-depth-256 -I/Library/Frameworks/R.framework/Resources/include     -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" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"    -fPIC  -mtune=core2 -O3    -c CAR.cpp -o CAR.o
clang++ -arch x86_64 -ftemplate-depth-256 -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 sourceCpp_15736.so CAR.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in sourceCpp("~/RA2015/Code/BYMCAR/CAR.cpp") : 
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install Command Line Tools for XCode (or equivalent).

我已经安装了Xcode的命令行工具,我的gfortran版本是4.9.0但是当我输入时

gfortran --version

它有以下错误:

 gfortran: warning: couldn’t understand kern.osversion ‘14.1.0

当我使用R 3.1.2时,我以前没有遇到过这个问题!

感谢您的帮助!

经过一番查找,我在网上找到了一个解决方案。

如果你对我有同样的问题,只需键入

curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

在终端上,源Cpp可以顺利运行。

有关详细说明,请访问[http://www.thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error]