这是Rcpp中Element-Wise Matrix Multiplication问题的后续内容
自升级到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
Run Code Online (Sandbox Code Playgroud)
评论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
Run Code Online (Sandbox Code Playgroud)
提前致谢.
更新
根据以下Kevin和Dirk的回复建议,我重新安装了Rcpp,RcppArmadillo并从源代码内联并更新了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
Run Code Online (Sandbox Code Playgroud)
Kev*_*hey 10
编辑:如果您是Homebrew用户,您现在需要使用brew install gcc(gfortran不再单独提供gcc),然后您可以按照此处的说明进行设置.
您必须/usr/local/lib手动将库符号链接:
ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/
我认为brew link gfortran会处理这个,但显然它只是符号链接gfortran程序而不是实际的库.所以,不幸的是,你必须自己做.
(替换4.8.2为gfortran您使用的任何版本homebrew.)
或者,如果您想要不进行修改/usr/local/lib,则可以使用
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
Run Code Online (Sandbox Code Playgroud)
在你的~/.R/Makevars文件中,所以R知道在哪里找到gfortran库.
| 归档时间: |
|
| 查看次数: |
3598 次 |
| 最近记录: |