[Rcpp-devel] [RcppExamples] -- would someone share the makefile?

Davor Cubranic cubranic at stat.ubc.ca
Mon Aug 23 19:50:33 CEST 2010


On 2010-08-21, at 1:30 PM, Johannes Egner wrote:

> Now using Rcpp.package.skeleton is indeed a step forward -- it passes R CMD, becomes a tarball, and I can build a zip file with the DLL in it. (Which correctly exposes the function rcpp_hello_world). It seems R CMD build miraculously knows how to feed the right arguments to the compiler (and lets it know where all the headers are). As convenient as this is, it is a bit too opaque for me. I suspect I'd struggle to develop "realistic code" (several files, links to static/dynamic libraries,...) just relying on R's package building mechanism. 
> 
> Long story short: something as in (1), i.e. a simple, but %working% piece of code where all "mechanics" (dependencies, compiler arguments, etc) are transparent is what I'm after. I would imagine that this could be done by explaining what happens behind the stages when R CMD build is called, and that these mechanics are best scaled to code projects of realistic sizes by the mentioned makefiles -- but I might of course be wrong.
> 

I develop realistic code, by your definition, and I use the structure created by Rcpp.package.skeleton. (Actually, RcppArmadillo.package.skeleton, but it doesn't make any difference to this discussion.) It has never caused me any problems. 

Some of my packages do not use Rcpp, but still have an almost identical layout and contents.You're developing an R extension, so you should play by R's extension rules, which means you don't use a Makefile and let R handle the compilation. (That's why you use 'R CMD ...' to build and install your software.) Have you read the R documentation on this [1]? If you haven't, please do, and it will clarify some things.

Now, as for the Rcpp includes you need, you get those because there is a 'LinkingTo: Rcpp' line in the DESCRIPTION file of your package, so R adds that package to the -I and -L paths during compilation. If there are any other includes or libraries that you need, or indeed any compiler arguments you want to set, you pass them by setting variable names in src/Makevars file of your package. For an example, see how PKG_LDFLAGS is set by the Makevars created by the Rcpp.package.skeleton command.

Finally, if you need multiple files, you just put them in 'src'. Everything in there will get compiled.

I hope this helps,

Davor

[1] http://cran.r-project.org/doc/manuals/R-exts.html


More information about the Rcpp-devel mailing list