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

时间:2015-03-24 03:48:33

标签: c++ r xcode osx-yosemite gfortran

我最近安装了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时,我之前没遇到过这个问题!

感谢任何帮助!

1 个答案:

答案 0 :(得分: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 /
终端上的

和sourceCpp可以顺利运行。

详细说明可在[http://www.thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error]

找到