我试图在 R 中运行这种和平的代码(感谢作者):
require(Rcpp)
require(RcppArmadillo)
require(inline)
cosineRcpp <- cxxfunction(
signature(Xs = "matrix"),
plugin = c("RcppArmadillo"),
body='
Rcpp::NumericMatrix Xr(Xs); // creates Rcpp matrix from SEXP
int n = Xr.nrow(), k = Xr.ncol();
arma::mat X(Xr.begin(), n, k, false); // reuses memory and avoids extra copy
arma::mat Y = arma::trans(X) * X; // matrix product
arma::mat res = (1 - Y / (arma::sqrt(arma::diagvec(Y)) * arma::trans(arma::sqrt(arma::diagvec(Y)))));
return Rcpp::wrap(res);
')
并得到,经过几次修复,以下错误:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created!
clang: error: no such file or directory: '/usr/local/lib/libfontconfig.a'
clang: error: no such file or directory: '/usr/local/lib/libreadline.a'
make: *** [file5a681e35ebe1.so] Error 1
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file5a681e35ebe1.cpp 2> file5a681e35ebe1.cpp.err.txt' had status 1
我过去经常使用 Rcpp。但是从现在到现在,我的计算机已经重新格式化,并且所有安装都使用自制软件重新完成。
我cairo
用brew安装:brew install cairo
该libreadline.a
错误已通过以下方式解决:
brew link --force readline
libfontconfig.a
但是由于已经链接,因此同样不起作用:
brew link --force fontconfig
Warning: Already linked: /usr/local/Cellar/fontconfig/2.11.1
To relink: brew unlink fontconfig && brew link fontconfig
我会假设那fontconfig
是在cairo
. 事实上,当我输入
brew install fontconfig
Warning: fontconfig-2.11.1 already installed
但事实是没有libfontconfig.a
at /usr/local/lib/
:
ls /usr/local/lib/libfont*
/usr/local/lib/libfontconfig.1.dylib
/usr/local/lib/libfontconfig.dylib
使用非常可疑的方法去这里下载它,代码运行,但仍然给出相应的警告,因为该文件对应于不同的 os.x 架构(我没有找到 10.9 的架构):
+ . + ld: warning: ignoring file /usr/local/lib/libfontconfig.a, missing required architecture x86_64 in file /usr/local/lib/libfontconfig.a (2 slices)
所以在这个阶段我有点失落。
如何安装libfontconfig.a
或查找 10.9 版本?
万一有什么用,我安装了 Xcode,我在 Mac 10.9.5 上,基于这个非常好的和详细的答案,我的~/.R/Makevars
文件看起来像:
CC=clang
CXX=clang++
FLIBS=-L/usr/local/bin/