Using C ++ in compilation error R: "RcppArmadillo.h: No such file or directory"

$ 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.his under

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

I wonder how to indicate your path to the compiler?

my.cpp as follows:

#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 Rcppand RcppArmadillo, therefore, I think they are also the last.

Thank you and welcome!

+4
source share
1 answer

You cannot just R CMD SHLIBthis file. Since you are using Rcpp attributes, you need to create code from Rcpp::dependsand Rcpp::export.

sourceCpp( 'my.cpp' ) R, , compileAttributes devtools::load_all, , .

R CMD SHLIB .

- $PATH RcppScript script:

#!/usr/bin/Rscript

args <- commandArgs(TRUE)

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

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

:

$ RcppScript my.cpp
+6

Source: https://habr.com/ru/post/1540516/


All Articles