Tim*_*Tim 6 c++ r armadillo rcpp
$ export PKG_CPPFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'`
$ export PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'`
$ R CMD SHLIB my.cpp
g++ -I/usr/share/R/include -DNDEBUG -I/usr/local/lib/R/site-library/Rcpp/include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c my.cpp -o my.o
my.cpp:3:27: fatal error: RcppArmadillo.h: No such file or directory
compilation terminated.
make: *** [my.o] Error 1
Run Code Online (Sandbox Code Playgroud)
我RcppArmadillo.h在
$ locate -i RcppArmadillo.h
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h
Run Code Online (Sandbox Code Playgroud)
我想知道如何指定其编译器的路径?
my.cpp 好像:
#include <RcppArmadillo.h>
#include <math.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
...
Run Code Online (Sandbox Code Playgroud)
我的操作系统是Ubuntu 12.04.R是R版本3.1.0(2014-04-10).我刚安装Rcpp和RcppArmadillo,所以我想他们也是最近的.
感谢致敬!
你不能只是R CMD SHLIB这个文件.因为您使用Rcpp属性,所以需要从Rcpp::depends和生成一些代码Rcpp::export.
sourceCpp( 'my.cpp' )如果您只是想要独立使用该文件,或者使用各种工具,compileAttributes或者devtools::load_all如果此文件是您正在开发的软件包的一部分,则可以从R 调用.
但是R CMD SHLIB不会为你生成额外的代码.
我对我的一些东西$PATH发现非常有用的是这个RcppScript脚本:
#!/usr/bin/Rscript
args <- commandArgs(TRUE)
if( "-v" %in% args ){
options( verbose = TRUE )
}
library(Rcpp)
sourceCpp( tail(args,1) )
Run Code Online (Sandbox Code Playgroud)
这样你就可以做到:
$ RcppScript my.cpp
Run Code Online (Sandbox Code Playgroud)