compileAttributes不会将本地标头复制到RcppExports.cpp

时间:2022-09-08 14:57:48

Here is my R_API.cpp

这是我的R_API.cpp

#include "include/R_GatingSet.hpp" 
#include <Rcpp.h>

Rcpp::List getPopCounts(Rcpp::XPtr<GatingSet> gsPtr, StringVec sampleNames, StringVec subpopulation, bool flowJo, bool isFullPath){
//do stuff
}

And here is RcppExports.cpp generated by compileAttributes

这是由compileAttributes生成的RcppExports.cpp

#include <Rcpp.h>
using namespace Rcpp;

// getPopCounts
Rcpp::List getPopCounts(Rcpp::XPtr<GatingSet> gsPtr, StringVec sampleNames, StringVec subpopulation, bool flowJo, bool isFullPath);
RcppExport SEXP flowWorkspace_getPopCounts(SEXP gsPtrSEXP, SEXP sampleNamesSEXP, SEXP subpopulationSEXP, SEXP flowJoSEXP, SEXP isFullPathSEXP) {
BEGIN_RCPP
    SEXP __sexp_result;
    {
        Rcpp::RNGScope __rngScope;
        Rcpp::traits::input_parameter< Rcpp::XPtr<GatingSet> >::type gsPtr(gsPtrSEXP );
    Rcpp::traits::input_parameter< StringVec >::type sampleNames(sampleNamesSEXP );
}

Apparently this fails the compiler because it misses the local header include (R_GatingSet.hpp) that defines the user class GatingSet.

显然这会使编译器失败,因为它错过了定义用户类GatingSet的本地头包含(R_GatingSet.hpp)。

g++ -I/home/wjiang2/R/r-devel/build/include -DNDEBUG -DROUT -Wno-deprecated -I/home/wjiang2/mylib/include/libxml2  -Ibst/ -I/usr/local/include -I"/home/wjiang2/R/r-devel/build/library/Rcpp/include"   -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:9:36: error: ‘GatingSet’ was not declared in this scope

I wonder if there is better solution other than manually adding this include back to RcppExports.cpp?

我想知道除了手动添加这个包括回RcppExports.cpp之外还有更好的解决方案吗?

1 个解决方案

#1


5  

You should be able to handle this by having a header file of the same name as your package in (assuming the package is flowWorkspace):

你应该能够通过一个与你的包同名的头文件来处理这个问题(假设包是flowWorkspace):

inst/include/flowWorkspace.h

compileAttributes will include that header file in RcppExports.cpp, and in there you could include the definitions of classes you need for the rest of the exports machinery to work.

compileAttributes将在RcppExports.cpp中包含该头文件,并且在那里您可以包含其他导出机制所需的类的定义。

EDIT: You could also try using the // [[Rcpp::interfaces(r, cpp)]] attribute to auto-generate these interfaces for you (although I haven't played around with that as much), but it is discussed in the Rcpp Attributes vignette -- see 3.5.1.

编辑:您也可以尝试使用// [[Rcpp :: interfaces(r,cpp)]]属性为您自动生成这些接口(虽然我没有那么多地使用它),但是它已经讨论过了在Rcpp属性小插图中 - 见3.5.1。

#1


5  

You should be able to handle this by having a header file of the same name as your package in (assuming the package is flowWorkspace):

你应该能够通过一个与你的包同名的头文件来处理这个问题(假设包是flowWorkspace):

inst/include/flowWorkspace.h

compileAttributes will include that header file in RcppExports.cpp, and in there you could include the definitions of classes you need for the rest of the exports machinery to work.

compileAttributes将在RcppExports.cpp中包含该头文件,并且在那里您可以包含其他导出机制所需的类的定义。

EDIT: You could also try using the // [[Rcpp::interfaces(r, cpp)]] attribute to auto-generate these interfaces for you (although I haven't played around with that as much), but it is discussed in the Rcpp Attributes vignette -- see 3.5.1.

编辑:您也可以尝试使用// [[Rcpp :: interfaces(r,cpp)]]属性为您自动生成这些接口(虽然我没有那么多地使用它),但是它已经讨论过了在Rcpp属性小插图中 - 见3.5.1。