[Rcpp-devel] How to link a .lib file in a rcpp-package in a Windows environment?

Dirk Eddelbuettel edd at debian.org
Mon Apr 25 13:46:41 CEST 2011


Hi Bernhard, 

On 25 April 2011 at 12:35, Bernhard Pollner wrote:
| Hello Dirk,
| 
| 
| Am 25.04.2011 um 04:54 schrieb Dirk Eddelbuettel:
| 
| > 
| > You need to include headers for R too, e.g. 
| > 
| >  #include <R.h>
| >  #include <Rdefines.h>
| > 
| > and maybe 
| > 
| >  #include <Rinternals.h>
| 
| I did that, so, the "final" C document looks like:
| 
| 
| > | > #include "plastic.h"   // adapt to what Plastic needs
| >  #include <R.h>
| >  #include <Rdefines.h>
| >  #include <Rinternals.h>
| >  > SEXP simpleText(void) {		      // no arguments
| > | > 
| > | >   Rprintf("hello world--before call\n");
| > | > 
| > | >   int x = aCallFromPlasticLibrary();  
| > | > 
| > | >   Rprintf("hello world--after call\n");
| > | > 
| > | >   return R_NilValue
| > | > }
| 
| 
| 
| With that it works, Rcmd check runs through nicely, I can install the package. I do not know how to load and run "simpleText()", though, 

As Doug likes to say: "If everything else fails, consider reading the
documentation" :) All this is explained in 'Writing R Extensions' and you
need to know about it too when using Rcpp functions.  Look up .Call() ....

but that probably does not matter. So I assume that, without using Rcpp and having only

| 	PKG_CPPFLAGS=-I.
| 	PKG_LIBS=PsyREG.lib
| in the Makevars.win, things are ok.

Ok, good.
 
| > | In the latter case, now what would be the line I would have to add to Makevars.win, or how do I have to modify the PKG_LIBS Line in order to incorporate "Plastic.lib"?
| > 
| > You probably want to look at a few packages using external libraries; there
| > are a few that use the GSL.  One of them is mvabund which also uses Rcpp. It
| > has 
| > 
| > ## This assumes that the LIB_GSL variable points to working GSL libraries
| > ## It also assume that we can call Rscript to ask Rcpp about its locations
| > PKG_CPPFLAGS=-std=c++0x -I$(LIB_GSL)/include
| > PKG_LIBS=-L$(LIB_GSL)/lib -lgsl -lgslcblas $(shell $(R_HOME)/bin/Rscript.exe -e "Rcpp:::LdFlags()")
| > 
| 
| Ok, I am working on that now, try to understand what it means and modify the lines to my own needs.
| I´let you know how things are going here soon...
| 
| 
| Meanwhile thanks a lot,

Pleasure!  You are making good progress.

Cheers, Dirk

| Bernhard
| 
| 
| 
| > but understand that the environment variable use here is 'just for CRAN' and
| > you do not have to worry about it.
| > 
| > You do need to understand what these two lines do though, which is why I
| > recommended that you start with something simple.
| > 
| > Hope this helps,  Dirk
| > 
| > | 

-- 
Gauss once played himself in a zero-sum game and won $50.
                      -- #11 at http://www.gaussfacts.com


More information about the Rcpp-devel mailing list