[Rcpp-devel] Specify include path with Rcpp.plugin.maker

Vaclav Petras wenzeslaus at gmail.com
Fri Jul 20 09:55:21 CEST 2012


On 19 July 2012 22:48, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 19 July 2012 at 09:17, Vaclav Petras wrote:
> | On 18 July 2012 18:33, Dirk Eddelbuettel <edd at debian.org> wrote:
> | >
> | > On 18 July 2012 at 18:21, Vaclav Petras wrote:
> | > | I used it just as an minimal working example. I'm sorry for confusion.
> | > |
> | > | I need it for _truly new libraries_ and same would apply also for my
> | > | own library if i have some.
> | > |
> | > | As I see I didn't include to my previous email explicit sentence
> | > | stating that I need really custom include path. So here it is.
> | >
> | > As I said, you probably want autoconf / configure to automate the search for
> | > headers and resulting configuration.
> | >
> | Yes, if I will do something more (and real) I will need some configure
> | for sure. But still, if it is possible to set flags for linking (-L
> | and -Wl,-rpath), for me it makes sense that some straightforward way
> | how to set include paths (-I) and additional compiler options should
> | exists. In another words, I would expect that Rcpp.plugin.maker will
> | have not only 'libs' parameter but also 'include.path' and 'flags'
> | parameters.
> |
> | > What is your use case?
> |
> | My use case is calling GRASS library functions from R [1]. I didn't
> | started yet and so far it is not clear what to do. I'm just exploring
> | the possibilities now. As a developer I don't have GRASS in standard
> | path and I want to do some ad-hoc tests and for them Rcpp.plugin.maker
> | is ideal solution. But I think that this approach can be used by
> | regular (power) users to write some one-purpose R script (with
> | Rcpp+inside).
>
> You could copy and extend our plugin code to provide a plugin in your
> package. Rcpp never needed external -I flags as it brings its own headers,
> same with RcppArmadillo etc pp.
>
> The plugin for RcppGSL may be an example, it does set PKG_CPPFLAGS to find
> GSL headers. See R/inline.R of the RcppGSL package.
>
> Dirk

Thanks, RcppGSL seems to be a good example of linking to custom
library. (I have to study it more.)

The lines

 plugin <- Rcpp:::Rcpp.plugin.maker(...
 settings <- plugin()
 settings$env$PKG_CPPFLAGS <- "your include paths and flags here"

were what I was looking for. I saw the line settings$env$PKG_CPPFLAGS
in FAQ but I didn't get how the settings object should be obtained
from plugin object returned by Rcpp.plugin.maker. Now I tested this
but it does not work. I suppose that I should do something with
modified settings object.

Since other things in Rcpp work so well (as far as I tried), I think
that setting of -I flag also should be done easily. However, as a next
step I will probably try to build a R package using Rcpp.

Thanks for help and just to say everything I appended my code.

Vaclav

 # again a dummy example with GSL

 # with this it works
 #Sys.setenv(PKG_CXXFLAGS="-I/usr/include/gsl/")

 plug <- Rcpp:::Rcpp.plugin.maker(
 include.before = "#include <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"
 ))

 # with this not
 settings = plug()
 settings$env$PKG_CPPFLAGS = paste("-I/usr/include/gsl", sep="")

 registerPlugin("gslDemo", plug )
 ...

cxxfunction result is "error: gsl_rng.h: No such file or directory..."

>
> | > Are you sure you don't want to build a package?  In
> | > that case you'd modify src/Makevars and would not need the plugin which is
> | > just used for smaller-scale use via inline.
> | >
> | As you can see, I'm not sure what to do. However, building a package
> | is highly probable. But I got the impression that some plugin for
> | inline package have to be the part of a package if I want to enable to
> | write custom functions which use some library other than standard C++
> | lib.
> |
> | [1] http://lists.osgeo.org/pipermail/grass-stats/2012-July/001422.html
>
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list