这是我的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
}


这是RcppExports.cpp生成的compileAttributes

#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 );
}


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

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


我想知道是否有比将其包含手动添加回RcppExports.cpp更好的解决方案?

最佳答案

您应该能够通过使用与您的包同名的头文件来处理此问题(假设包为flowWorkspace):

inst/include/flowWorkspace.h


compileAttributes将在RcppExports.cpp中包含该头文件,并且在其中可以包含使其余导出机制正常工作所需的类的定义。

编辑:您也可以尝试使用// [[Rcpp::interfaces(r, cpp)]]属性为您自动生成这些接口(尽管我还没有那么多地尝试过),但是它在Rcpp Attributes vignette中进行了讨论-请参见3.5.1。

08-19 09:42