OS X Mavericks 上的 RcppArmadillo 编译错误 [英] RcppArmadillo Compile Errors on OS X Mavericks

查看:37
本文介绍了OS X Mavericks 上的 RcppArmadillo 编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对 Rcpp 中的Element-Wise Matrix Multiplication 中的问题的跟进

自从升级到 Mavericks 以来,我在使用 RcppArmadillo 时遇到了许多不同类型的错误.我安装了 Xcode 5.0.2 和命令行工具.另外,来自 Homebrew 的 gfortran.但我一直遇到下面的错误 --

I have been getting a number of different kinds of errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and Command Line Tools installed. Also, gfortran from Homebrew. But I keep encountering the error below --

> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) 
                       { return(a % b); }", depends="RcppArmadillo")


ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_18474.so] Error 1
clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include  -    I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppArmadillo/include"    -fPIC  "-mtune=native -g -O2 -Wall -pedantic -Wconversion" -c fileaf992bfb8f84.cpp -o fileaf992bfb8f84.o clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o sourceCpp_18474.so fileaf992bfb8f84.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -lgfortran /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation 
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  : 
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).

# Contents of Makevars
$ cat ~/.R/Makevars 
CC=clang
CXX=clang++ 
CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
FLIBS=-lgfortran

评论 FLIBS=-lgfortran 没有帮助,会导致更多错误消息 --

Commenting FLIBS=-lgfortran does not help and results in even more error messages --

> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo")
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)
make: *** [sourceCpp_50381.so] Error 1

提前致谢.

更新

根据下面 Kevin 和 Dirk 的回复建议,我重新安装了 Rcpp、RcppArmadillo 和内联源,并更新了 FLIBS 以指向实际目录.这解决了问题.

Following suggestions from response from Kevin and Dirk below, I re-installed Rcpp, RcppArmadillo and inline from source and updated FLIBS to point to the actual directory. This solved the issue.

# Update FLIBS in ~/.R/Makevars
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
#Re-Install from source
install.packages(c("Rcpp","RcppArmadillo","inline"),type="source")
#Restart R

推荐答案

如果您是 Homebrew 用户,您现在需要使用 brew install gcc (gfortrancode> 不再与 gcc 分开提供),然后您可以按照说明此处 进行设置.

If you're a Homebrew user, you now instead need to use brew install gcc (gfortran is no longer provided separate of gcc), and you can then follow the instructions here to get set up.

您必须手动将库符号链接到 /usr/local/lib:

You have to symlink the libraries to /usr/local/lib manually:

ln -s/usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.*/usr/local/lib/

我认为 brew link gfortran 会处理这个问题,但显然它只是符号链接 gfortran 程序而不是实际的库.所以,不幸的是,你必须自己做.

I thought brew link gfortran would handle this, but apparently it only symlinks the gfortran program and not the actual libraries. So, unfortunately, you have to do it yourself.

(将 4.8.2 替换为您从 homebrew 使用的任何版本的 gfortran.)

(Replace 4.8.2 with whichever version of gfortran you're using from homebrew.)

或者,如果你不想修改/usr/local/lib,你可以使用

Alternatively, if you want to keep from modifying /usr/local/lib, you can use

FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran

在你的 ~/.R/Makevars 文件中,所以 R 知道在哪里可以找到 gfortran 库.

in your ~/.R/Makevars file instead, so R knows where to find the gfortran libraries.

这篇关于OS X Mavericks 上的 RcppArmadillo 编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆