Код: Выделить всё
Rscript -e 'Rcpp::Rcpp.package.skeleton("soq")'
Код: Выделить всё
#include
#include
class Echo {
private:
std::string message;
public:
Echo(std::string message) : message(message) {}
Echo(SEXP);
std::string get() { return message; }
};
#include
using namespace Rcpp;
RCPP_MODULE(echo_module) {
class_("Echo")
.constructor()
.method("get", &Echo::get)
;
};
//// [[Rcpp::export]]
void shout(Echo e) {
Rcout library(Rcpp)
R> suppressMessages(library(inline))
R> library(soq)
R> echo_module Echo e print(e$get())
Код: Выделить всё
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘soq’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/brj/R/x86_64-pc-linux-gnu-library/3.6/00LOCK-soq/00new/soq/libs/soq.so':
/home/brj/R/x86_64-pc-linux-gnu-library/3.6/00LOCK-soq/00new/soq/libs/soq.so: undefined symbol: _ZN4EchoC1EP7SEXPREC
Error: loading failed
Execution halted
ERROR: loading failed
Я использую R.3.6.3 и
Код: Выделить всё
R> sessionInfo()
....
other attached packages:
[1] inline_0.3.15 Rcpp_1.0.4.6
....
Для тех, кто пытается следовать приведенному выше примеру: очень важно, чтобы исходный файл имел точное имя
_types.h. В противном случае автоматически сгенерированный файл RcppExports.cpp не будет #include, и, следовательно, класс Echo не будет там определен. Это приведет к ошибке компиляции.
Подробнее здесь: https://stackoverflow.com/questions/622 ... rcppexport