繁体   English   中英

Rcpp:将包中的标头包含到cppFunction中

[英]Rcpp: Include header from package into cppFunction

我有一个使用Rcpp的软件包。 它具有int src/testr.h定义的不同C++函数。 现在在某个时候,我需要生成Rcpp函数(使用cppFunctioncxxfunction ), Rcpp函数使用src/testr.h定义的东西。 我怎样才能做到这一点?

我试过了,

> 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))

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

     ^      

快速建议:

  1. 将标题移至inst/include/testr.h ;
  2. 这需要一个src/Makevars条目(例如PKG_CPPFLAGS = -I../inst/include才能使编译看起来在那里。
  3. 现在安装了软件包,例如mypkg ,您可以添加depends="mypkg" ,R将知道为您设置-I...

我们一直在例如BH和各种Rcpp*软件包中使用相同的技巧。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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