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

Dirk Eddelbuettel edd at debian.org
Wed Sep 4 19:30:08 CEST 2013


On 4 September 2013 at 18:51, Simon Zehnder wrote:
| 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_

Briefly:

 i)   Please show the actual linking step.

 ii)  Mixing shared and static is a bit messy, but I have done it too I
      think. You may want to try _an absolute path_ to the .a library,
      and a different link position, eg place ${NLOPT_LIBS} first.

This is definitely doable.

Dirk


| 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
| 
| 
| _______________________________________________
| 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