公开Rcpp模块

时间:2016-12-24 16:21:35

标签: c++ r rcpp

我在处理里面的例子时遇到了一些麻烦:

http://dirk.eddelbuettel.com/code/rcpp/Rcpp-modules.pdf

具体来说,第2.2节,作者在RCPP中公开C ++类并使其可以在R中调用。

我将代码复制到一个新的RCPP文件中并且没有任何问题但是在我在R中运行以下内容时遇到错误:

require(Rcpp)
require(inline)
unif_module <- Module( "unif_module", getDynLib(fx_unif ) )

错误:

Error in getDynLib(fx_unif) : 
  error in evaluating the argument 'x' in selecting a method for function 'getDynLib': Error: object 'fx_unif' not found

然后我浏览了使用getDynLib的文档的其他部分,发现它们都没有初始化传递给getDynLib的参数。我的问题是什么是fx_unif

谢谢,

更新

因此,我试着在论文中的另一个例子:

inc = '
class Uniform {
public:
  Uniform(double min_, double max_) : min(min_), max(max_) {}
  NumericVector draw(int n) const {
    RNGScope scope;
    return runif( n, min, max );
  }
  double min, max;
};

double uniformRange( Uniform* w) {
  return w->max - w->min;
}
RCPP_MODULE(unif_module) {
  class_<Uniform>( "Uniform" )
  .constructor<double,double>()
  .field( "min", &Uniform::min )
  .field( "max", &Uniform::max )
  .method( "draw", &Uniform::draw )
  .method( "range", &uniformRange )
  ;
}
'

fx_unif = cxxfunction(signature(), plugin="Rcpp", include=inc)

错误:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="filef4028245a6f.dll" WIN=64 TCLBIN=64 OBJECTS="filef4028245a6f.o"' had status 127 
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-32~1.2/bin/x64/R CMD SHLIB filef4028245a6f.cpp 2> filef4028245a6f.cpp.err.txt' had status 1 

0 个答案:

没有答案