[Rcpp-devel] Plugin example

Dirk Eddelbuettel edd at debian.org
Mon Jun 1 19:25:15 CEST 2015


On 1 June 2015 at 19:06, Wagner Bonat wrote:
| Dear all,
| 
| I am starting to study the Rcpp package. I am reading the Rcpp book, butI have
| a problem on Listing 2.8 from Rcpp book. This listing is about Creating
| Plugins.
| 
| 
| ## The C++ code
| gslrng <-'
| int seed = Rcpp::as<int>(par) ;
| gsl_rng_env_setup();
| gsl_rng *r = gsl_rng_alloc (gsl_rng_default);
| gsl_rng_set (r, (unsigned long) seed);
| double v = gsl_rng_get (r);
| gsl_rng_free(r);
| return Rcpp::wrap(v);
| '
| 
| ## Creating the plugin
| plug <- Rcpp:::Rcpp.plugin.maker(
|     include.before = "#include <gsl/gsl_rng.h>",
|      libs = paste("-L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp",
|                   "-Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib",
|                   "-L/usr/lib -lgsl -lgslcblas -lm"))
| 
| ## Run
| registerPlugin("gslDemo", plug)
| fun <- cxxfunction(signature(par="numeric"), gslrng, plugin ="gslDemo", verbose
| =TRUE)
| 
| When I try compile I received this error message
| 
| Error in compileCode(f, code, language = language, verbose = verbose) :
|   Compilation ERROR, function(s)/method(s) not created! /usr/bin/ld: cannot
| find -lRcpp
| collect2: error: ld returned 1 exit status
| make: *** [file1a3c6aca3e2e.so] Error 1

Excellent catch!  And new entry for the (still not really existing) errata page!

Since the book was finished in late 2012 and came out in mid 2013, Rcpp
changed: Romain realized that we could adopt the initialization scheme
offered by R and, with a fairly substantial amount of work, switched the code
this initialization.  Which means no more explicit libRcpp, and why the
linker says that you do not have one.

On my (current Ubuntu) system, the example works once you simply remove the
two linker lines for Rcpp making the whole shorter and simpler:


## Creating the plugin
plug <- Rcpp:::Rcpp.plugin.maker(
	include.before = "#include <gsl/gsl_rng.h>",
	libs = "-L/usr/lib -lgsl -lgslcblas -lm")


Cheers,  Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list