gpt4 book ai didi

xcode - OS X Mavericks 上的 RcppArmadillo 编译错误

转载 作者:行者123 更新时间:2023-12-04 13:50:57 26 4
gpt4 key购买 nike

这是 Element-Wise Matrix Multiplication in Rcpp 上问题的后续内容。

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

> 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没有帮助并导致更多错误消息 -
> 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 和 inline,并更新了 FLIBS 以指向实际目录。这解决了这个问题。
# 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 ( gfortran 不再与 gcc 分开提供),然后您可以按照说明 here设置。

您必须将库符号链接(symbolic link)到 /usr/local/lib手动:
ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/
我以为 brew link gfortran会处理这个,但显然它只是符号链接(symbolic link) gfortran程序而不是实际的库。所以,不幸的是,你必须自己做。

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

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

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

在您的 ~/.R/Makevars文件,所以 R 知道在哪里可以找到 gfortran图书馆。

关于xcode - OS X Mavericks 上的 RcppArmadillo 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19920281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com