首页 > 解决方案 > Rcpp 属性是否支持仅非标头的 Rcpp 模块库?

问题描述

如果我做:

Rcpp::Rcpp.package.skeleton("test1", module = TRUE)
Rcpp::Rcpp.package.skeleton("test2")

然后在test1src目录中,我只保留两个文件:

// rcpp_module.cpp
#include <Rcpp.h>
#include "rcpp_module.h"

std::string World::greet(){ return msg;  }

RCPP_MODULE(yada){
    using namespace Rcpp ;
    class_<World>("World")
    .constructor() // expose the default constructor
    .method("greet", &World::greet , "get the message")
    .method("set", &World::set     , "set the message")
    ;
}

// rcpp_module.h
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]

class World {
public:
  World() : msg("hello") {}
  void set(std::string msg) { this->msg = msg; }
  std::string greet(); // NOTE this is just the declaration
private:
  std::string msg;
};

加上单个loadModule调用:

# zzz.R
loadModule("yada", TRUE)

然后,在test2package中src,我有一个文件:

// rcpp_hello_world.cpp
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::depends(test1)]]
#include "rcpp_module.h"

// [[Rcpp::export]]
List rcpp_hello_world2(SEXP xptr) {
  Rcpp::XPtr<World> world_ptr(xptr);
  Rcout << world_ptr->greet() << std::endl;
  return List::create();
}

test2在和下都有test1它的描述。我也将's复制到目录。然而,当我尝试使用时收到一个未定义的符号:Depends:LinkingTo:test1rcpp_module.hinst/includetest2

Error in dyn.load(dllfile) : 
  unable to load shared object 'test2/src/test2.so':
  dlopen(test2/src/test2.so, 6): Symbol not found: __ZN5World5greetEv 

我究竟做错了什么?

标签: rcpp

解决方案


推荐阅读