简体   繁体   中英

Rcpp: Include header from package into cppFunction

I have a package that uses Rcpp . It has different C++ function defined int src/testr.h . Now at some point I need to generate Rcpp functions (using cppFunction or cxxfunction ) that use things defined in src/testr.h . How can I do that?

I tried,

> cxxfunction(signature(x="list") includes = c('#include "testr.h"'), body=sprintf(template, name, name))
> Rcpp::cppFunction(depends = "testr", includes = c('#include "src/testr.h"'), sprintf(template, name, name))

But

file7086270f0da.cpp:7:10: fatal error: 'testr.h' file not found
#include "testr.h"

     ^      

Quick suggestion:

  1. Move the header to inst/include/testr.h ;
  2. This requires a src/Makevars entry such as PKG_CPPFLAGS = -I../inst/include to have the compilation look there.
  3. Now with the package installed as, say, mypkg , you can add a depends="mypkg" and R will know to set a -I... for you.

We use the same trick all the time in eg BH and various Rcpp* packages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM