[Rcpp-devel] Symbol not found when including an external library

Simon Zehnder szehnder at uni-bonn.de
Wed Sep 4 18:51:03 CEST 2013


Dear Rcpp::Users, Rcpp::Devels,

I am following the ongoing discussion 'How to use external C++ libraries in R packages withRcpp' (Makevars are still one of my weaknesses) and I have a related question. 

I am trying to use the C++ optimization library nlopt (http://ab-initio.mit.edu/wiki/index.php/NLopt) in my package that is based on RcppArmadillo. In a first step I installed nlopt in a subfolder of the 'src' folder of my package structure (so I have '/src/nlopt-2.3'). Second, I included the header file into my source file right below '#include <RcppArmadillo.h>'. Then I set my Makevars file to:

## Use the R_HOME indirection to support installations of multiple R version
NLOPT_VERSION = 2.3

NLOPT_LIBS = -lm nlopt-${NLOPT_VERSION}/lib/libnlopt_cxx.a

NLOPT_INCL = -I./nlopt-${NLOPT_VERSION}/include

PKG_CPPFLAGS = ${NLOPT_INCL}
PKG_CFLAGS = -pipe ${NLOPT_INCL}
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` ${NLOPT_LIBS}

Calling 'R CMD INSTALL packageName' compiles without errors but produces the well-known error during loading the shared library:

Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.0/Resources/library/finmix/libs/finmix.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/finmix/libs/finmix.so, 6): Symbol not found: __ZNSt8__detail15_List_node_base11_M_transferEPS0_S1_

I find the missing symbol (using 'nm -A libnlopt_cxx.a | grep "transfer"' on the shell) in the static library of nlopt (libnlopt_cxx.a) to which I link in the Makevars, but I do not know yet, how I have to modify the Makevars to include also the static library of nlopt into the shared library of my package. Does anyone have a suggestion how to do it? 


Best

Simon




More information about the Rcpp-devel mailing list