Xiaobo Gu
Xiaobo Gu

Reputation: 189

How to build a R package which use Rcpp with external c++ libraries?

Such as boost, where can I specify the following:

1.External c++ header file include path 
2.External c++ source file 
3.External c++ link library file path

Upvotes: 13

Views: 6919

Answers (3)

John
John

Reputation: 1

Where I work, researchers are using Rcpp not to create packages but to incorporate C++ scripts in non-standard locations into their work in R 'on the fly' in a Linux OS.

We wanted to include multiple external C++ libraries but the following did not work:

Sys.setenv("PKG_LIBS = -lglpk -lsuperlu") 

For Rcpp to find them, we had to add -L for the paths and put them ahead of the -l statements:

Sys.setenv("PKG_LIBS= -L/PATH/TO/GLPK/LIB -L/PATH/TO/SUPERLU -lglpk -lsuperlu")  

Upvotes: 0

Metamorphic
Metamorphic

Reputation: 801

Dirk's paper "Thirteen Simple Steps for Creating An R Package with an External C++ Library" gives an example src/Makevars:

CXX_STD = CXX11
PKG_CFLAGS = -I. -DGMP -DSKIP_MAIN
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lgmpxx -lgmp

As you can see, additional libraries are specified in PKG_LIBS in this file. The src/Makevars approach assumes that you incorporate C++ code into your project using a standard package layout, as produced by Rcpp.package.skeleton(), with NAMESPACE and DESCRIPTION and so on.

According to Dirk's comments above, there is currently no way to specify an external library when C++ code is incorporated using the sourceCpp function, because that function provides an interface which is supposed to be multi-platform.

Upvotes: 5

Dirk is no longer here
Dirk is no longer here

Reputation: 368499

It all goes into src/Makevars as explained in

Upvotes: 15

Related Questions