I'm trying to use Rcpp to extend functionality from the BayesOpt C++ library into R. I'm a long-time R user but relatively new to C++ and I'm running into some problems. I've followed the Rcpp vignettes for setting up a package, which I understand is the best way to bring external C++ libraries in.
I've set PKG_CPPFLAGS and PKG_LIBS in src/Makevars to the BayesOpt include folders and library, and I have a single .cpp file (call it test.cpp) in src/ that uses #include for some header files from BayesOpt. In this file, I have // [[Rcpp::export]]
above the function I want to export.
When I run R CMD check mypackage
, the library seems to be working successfully -- looking at the log, everything goes well until it tries to load the package that was just "installed". Then, I get
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/me/p3/mypackage.Rcheck/mypackage/libs/mypackage.so':
/home/me/p3/mypackage.Rcheck/mypackage/libs/mypackage.so: undefined symbol: _ZTIN8bayesopt13DiscreteModelE
in the error log. echo _ZTIN8bayesopt13DiscreteModelE | c++filt
gives typeinfo for bayesopt::DiscreteModel
, which is the first object in my test.cpp file that uses the BayesOpt headers. I've looked high and low for a solution to this, but I can't seem to find one. I would like to believe that the Makevars points at the library correctly, because it is able to find the header files during the first installation check -- it's only when loading the candidate package that I get this undefined symbol error. I've looked at an Rcpp example that uses external libraries, but the one Dirk points to in the answers I've looked at, RcppGSL
, has a 3500+ line configure script that fills out the Makevars, and it's a little difficult to parse.
I would appreciate anyone's help -- my last resort is to dump everything into src
but that seems cumbersome and less than elegant for a library that is already neatly organized.