Re: [Rcpp-devel] linking external libraries in a package
Hi, Dirk was right, unsurprisingly, all it took was to dump the files in src/ and R takes care of everything during package building (I initially had issues with the PATH for my C compiler, which led me to the wrong conclusion that things weren't so simple). All is magically working now :) Thanks, baptiste On 1 January 2014 17:33, Dirk Eddelbuettel e...@debian.org wrote: 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 depends). 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. Cheers, Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] linking external libraries in a package
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 ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] linking external libraries in a package
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 depends). 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. Cheers, Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel