سؤال

$ 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

My RcppArmadillo.h is under

$ locate -i RcppArmadillo.h
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h

I wonder how to specify its path to the compiler?

my.cpp looks like:

#include <RcppArmadillo.h>
#include <math.h> 

// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
...

My OS is Ubuntu 12.04. R is R version 3.1.0 (2014-04-10). I just installed Rcpp and RcppArmadillo, so I guess they are also the most recent ones.

Thanks and regards!

هل كانت مفيدة؟

المحلول

You cannot just R CMD SHLIB this file. Because you use Rcpp attributes, you need some code to be generated from Rcpp::depends and Rcpp::export.

You can either call sourceCpp( 'my.cpp' ) from R if you just want standalone use of the file or use various tools such as compileAttributes or devtools::load_all if this file is part of a package you are developping.

But R CMD SHLIB is not going to generate the extra code for you.

Something I have on my $PATH and find quite useful is this RcppScript script:

#!/usr/bin/Rscript

args <- commandArgs(TRUE)

if( "-v" %in% args ){
  options( verbose = TRUE )
}

library(Rcpp)
sourceCpp( tail(args,1) )

So that you can do:

$ RcppScript my.cpp
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top