[Rcpp-devel] Sharing Cpp code between packages

Alessandro Mammana mammana at molgen.mpg.de
Tue May 20 17:26:34 CEST 2014

Dear All,
first of all thanks again for Rcpp, I am becoming more and more
dependent on it and I am filling my directories with .cpp scripts...

I have a Rcpp package P using some header file F.hpp in its src/
directory. This file F.hpp contains templated functions and structs.
Is there a way for a new Rcpp package Q to include file F.hpp?

I read already Writing R Extensions "Linking to native routines in
other packages" as well as Rcpp-attriibutes, "Providing a C++
Interface". It looks like there are two mechanisms for sharing c++
1. The "interface" mechanism: the real code is in the src/ directory
but it is referred to from some headers in the inst/include directory.
Additionally, these headers need to be wrapped with some (boilerplate
and obscure to me) C code. This works only with functions. The
boilerplate code can be nicely generated automatically with Rcpp
2. The "direct" mechanism: just put the code in inst/include and tweak
the Makevars so that the compiler knows where to look for those
headers. This should work also with structs and templated cpp code.

I think I need the "direct" mechanism.
In package P, I moved my hpp files in inst/include and tweaked the
Makevars, the package compiled fine.
Now in package Q I am trying to use some of the stuff, and I am
including the files I need. I also did the following:
1. put import(P) in Q's namespace file
2. put Import P and LinkingTo P in Q's description file

however during compilation I got an error like:
undefined symbol: _Z16rcpp_hello_worldv

do you know what could be wrong?
Thanks a lot and sorry for bothering.


Alessandro Mammana, PhD Student
Max Planck Institute for Molecular Genetics
Ihnestraße 63-73
D-14195 Berlin, Germany

More information about the Rcpp-devel mailing list