[Rcpp-devel] Error in Module
Brötje David
d.broetje at tu-braunschweig.de
Tue Apr 8 09:00:18 CEST 2014
Hello,
I want to expose a C++ class to R through Rcpp. For that I want to try
out a few examples from the note "Exposing C++ functions and classes
with Rcpp modules" and the book "Seamless R and C++ Integration with
Rpp". But I can't manage to get them work. It ends up with an error.
So this is what I'm doing.
First I create a cpp file with the c++ code from the example. The full
content of the cpp file is below.
------------------------------------------------------------------------------------
#include "Rcpp.h"
using namespace Rcpp;
std::string hello() { return "hello"; }
int bar( int x) { return x*2; }
double foo( int x, double y) { return x*y; }
void bla( ) { Rprintf( "hello\\n" ); }
void bla1( int x) {
Rprintf( "hello (x = %d)\\n", x );
}
void bla2( int x, double y) {
Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y );
}
RCPP_MODULE(yada) {
using namespace Rcpp;
function( "hello" , &hello );
function( "bar" , &bar );
function( "foo" , &foo );
function( "bla" , &bla );
function( "bla1" , &bla1 );
function( "bla2" , &bla2 );
}
------------------------------------------------------------------------------------
Then I run this command:
PKG_CXXFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'` PKG_LIBS=`Rscript -e
'Rcpp:::LdFlags()'` R CMD SHLIB test.cpp
Afterwards I start R and run these commands in R:
------------------------------------------------------------------------------------
require(Rcpp)
yada <- Module("yada")
yada$bar( 2L )
yada$foo( 2L, 10.0 )
yada$hello()
yada$bla()
yada$bla1( 2L)
yada$bla2( 2L, 5.0 )
------------------------------------------------------------------------------------
And it ends up with this error:
------------------------------------------------------------------------------------
Error in Module(module, mustStart = TRUE) :
Failed to initialize module pointer: Error in
FUN("_rcpp_module_boot_yada"[[1L]], ...): no such symbol
_rcpp_module_boot_yada in package .GlobalEnv
------------------------------------------------------------------------------------
This happens all the time with modules. Did I overlook something or
what am I doing wrong?
David
More information about the Rcpp-devel
mailing list