[Rcpp-devel] linking external libraries in a package
edd at debian.org
Wed Jan 1 21:33:24 CET 2014
On 1 January 2014 at 17:30, baptiste auguie wrote:
| Hi list, and happy new year,
Thanks, and Happy New Year from here too!
| 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 ).
Summary: No external depends. No extra headers. No extra libraries.
(Beyond the Accelerate framework which is OS X specific. I do not know if R
would add this automatically. If it needs manual intervention, you can
handle this with src/Makevars alone. But that is a different question.)
| 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.
Just drop it into src/ and you're done.
There are 5000+ packages on CRAN, and a "large enough" percentage with
compiled code, and a "still large enough percentage" amonth those which
includes external packages. Just look what others are doing -- eg packages
such as RSQLite include the entire SQLite project (plain C, no external
More complicated setups exists too where you first descend into
subdirectories of src/ and build entire libraries first. IIRC the Matrix
package does -- but you don't have to. One of the earlier Rcpp "clients"
which I helped with a package reorginisation was phylobase, and there we did
just that: copy all the external depends into src/ and have Makevars take
care of it. Which avoids the convoluted need for library building under
different OSs and ARCHs. As I said: drop into src/ and you're done.
R actually provides a pretty rich build system. If anything, it is a tad
underdocumented. But lists such as this one, or expert such as Simon, can
set you straight.
Let me know if you need more help. I could fork your repo if you're lost.
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel