[Rcpp-devel] How to use external C++ libraries in R packages with Rcpp.
Dirk Eddelbuettel
edd at debian.org
Mon Sep 2 18:10:47 CEST 2013
Hi Xiaobo,
On 2 September 2013 at 18:33, guxiaobo1982 wrote:
| We are going to package an external C++ library into a R package, and I'd like
| to know Rcpp can help a lot,
Yes, Rcpp can help a lot in that case.
Many existing packages provides examples, starting for example with RcppGSL
by Romain and myself and many other existing CRAN packages which connect to
external libraries using Rcpp.
We have an entire vignette devoted to using Rcpp for your package:
Rcpp-package. And my Rcpp book has a chapter on this too.
| but we have two sinarioes:
[ You probably meant "scenarios" ]
| 1. We have only c++ header files, .lib dynamic link file and .dll dynamic
| runtime library.
".lib" and ".dll" sounds a lot like Windows-only. Please understand that you
generally cannot link with Visual C++-compiled code (unless you do a pure C
layer in between, and even that is tricky.
But any "standard" library -- such as GSL, or anything else that is portable
and available on Windows, Linux and OS X can be used.
| 2. A whole C++ library with all the header and .cpp source file in a seperate
| directory.
That can be done too; you could build a static library first. The trick is to
avoid having to do a custom Makefile (as R prefers you do just use
src/Makevars or src/Makevars.win) so sometimes it is easier to just have all
the files in src/* --- I helped the folks with the phylobase package do just
that.
You can hardcode Windows path in src/Makevars.win, possibly using an
environment variable. Here is the one from RcppGSL:
## This assumes that the LIB_GSL variable points to working GSL libraries
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib -lgsl -lgslcblas $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")
For Unix one often uses configure but as a first approximation you can also
use environment variables on src/Makevars.
| In both sinarioes, how can I specify additional include pathes, add the
| additional sources, and link against external .lib files.
Please see the vignette, or the chapter in my book.
Dirk
| Regards,
|
| Xiaobo Gu
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list