[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 04:54:13 CEST 2011
Bernhard,
On 25 April 2011 at 04:32, Bernhard Pollner wrote:
04:32 -- burning the midnight oil? ;-)
| Hi Dirk,
|
| thank you for your answer.
|
| I tried to write a very simple, pure package (without Rcpp), with the C-File named "ROnlyTest", where I put the code like suggested by you.
|
| The Makevars.win contains now only: (*)
| PKG_CPPFLAGS=-I.
| PKG_LIBS=Plastic.lib
|
| Unfortunetely, I can not compile (fail at "Rcmd check ROnlyTest") --- and I get the following error-message:
| ROnlyTest.cpp:3:1: error: 'SEXP' does not name a type
You need to include headers for R too, e.g.
#include <R.h>
#include <Rdefines.h>
and maybe
#include <Rinternals.h>
depending on what R data structure and functions you use. See the "Writing R
Extensions" manual, as well as simple R packages with C sources -- such as
e.g. my old digest package (which does not use Rcpp).
| When I then write a "void" before the "SEXP", I get the error:
| expected initializer before 'simpleText'
| I am sure it is quite trivial, but I just do not know what to write as an "initializer".... , or to do this line just right.
|
| But, apart from that, when the only thing I write into the C-File is:
| #include "PlasticHeader.h"
| int x = CallAFunctionFromPlasticDotLib();
| then Rcmd check runs through nice, and I can build and install this package. Does that mean that the linking of Plastic.lib from above (*) was succesful?
|
| 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()")
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
|
|
| Thanks a lot,
| Bernhard
|
|
|
|
| >
| >
| > A really simple (untested) one would be something like
| >
| >
| > #include "whicheverHeaderYouNeed.h" // adapt to what Plastic needs
| >
| > SEXP simpleText(void) { // no arguments
| >
| > Rprintf("hello world--before call\n");
| >
| > // set up arguments as needed
| > someCallFromYourLibrarry(someArgs);
| >
| > Rprintf("hello world--after call\n");
| >
| > return R_NilValue; // because of the SEXP return value
| > }
| >
| >
| > See how you far you get with this...
|
--
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