[Rcpp-devel] linking external libraries in a package

baptiste auguie baptiste.auguie at gmail.com
Wed Jan 1 20:30:35 CET 2014


Hi list, and happy new year,

This is a follow-up to a previous query I made on Stack Overflow,
http://stackoverflow.com/questions/20474303/using-c-function-from-other-package-in-rcpp
where my goal is to use an existing library for numerical integration
together with my existing functions using RcppArmadillo.

I've since taken a different perspective: I will call directly the original
C routine and ship it with my package. With helpful guidance from Conrad
Sanderson I managed to sort out the c/c++ side of things. I now have a
stand-alone proof-of-principle code to use the cubature library for
numerical integration, with an integrand based on Armadillo objects (and
some glue between the two),
https://github.com/baptiste/cubature/blob/master/minimal.c

The command I'm using to create an executable is

g++ -DHCUBATURE -o minimal hcubature.c minimal.c -lm -I /usr/local/include
-O2  -larmadillo -framework Accelerate

where hcubature.c and associated header files come from cubature (
http://ab-initio.mit.edu/wiki/index.php/Cubature ).

The last piece I'm missing is how to compile such source files in a package
with the correct flags; my understanding is that most of these flags can be
taken care of with a suitable Makevars file. I currently have the following,

PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" )
$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

but I don't see how to link hcubature.c together with another source file.
Do I need a complete Makefile to specify this sort of command? I have zero
experience in these matters of compilation, I'd appreciate some guidance or
simple examples to follow.

Best regards,

baptiste
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140101/16c16cfd/attachment.html>


More information about the Rcpp-devel mailing list