这是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并从源代码内联并更新了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
答案 0 :(得分:10)
编辑:如果您是自制软件用户,则现在需要使用brew install gcc
(gfortran
不再单独提供gcc
),然后您可以按照说明进行操作here要设置。
您必须手动将库符号链接到/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
在您的~/.R/Makevars
文件中,因此R知道在哪里找到gfortran
库。
答案 1 :(得分:1)
我只能建议你研究r-sig-mac list上的众多主题,SO上的不同答案以及rcpp-devel list上的帖子。
由于您的错误来自Fortran链接失败,因此也可以查看the standard page by Simon U.以及tools page点。 AFAIK你应该使用R的那个页面使用(较旧的)gfortran 4.2。*,但是我不是OS X用户。
2016年末编辑:我们现在在section 2.16 of the Rcpp FAQ中有更详细的说明。