I'm using Boost.Python to embed C++ code in my Python app. The module builds fine with a few warnings. When I import the module in Python I get this error:
ImportError: .../cdtm_ext.so: undefined symbol: gsl_multimin_fdfminimizer_conjugate_fr
This symbol is defined in an external library (Gnu Scientific Library) header file, and the symbol exists in the .so file:
$ nm cdtm_ext.so | grep gsl_multimin_fdfminimizer_conjugate_fr
U gsl_multimin_fdfminimizer_conjugate_fr
Here is my Jamroot
file:
import python ;
if ! [ python.configured ]
{
ECHO "notice: no Python configured in user-config.jam" ;
ECHO "notice: will use default configuration" ;
using python ;
}
use-project boost
: ../../../.. ;
project
: requirements
<library>/boost/python//boost_python
<include>/usr/local/include/gsl
;
python-extension cdtm_ext : cdtm.boost.cpp cdtm/cdtm-model.cpp cdtm/corpus.cpp cdtm/main.cpp cdtm/opt.cpp cdtm/utils.cpp : <library-path>/usr/local/include/gsl ;
install convenient_copy
: cdtm_ext
: <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION
<location>.
;
I had a similar problem when I wrote my own extension using low-level C++ interface. I fixed the problem there by adding the library name gsl
in the libraries list of the Extension
function call. module = Extension(... libraries = ['gsl', 'cblas'] ...)
. I have no idea how to do the same thing with Boost.Python.
The symbol gsl_multimin_fdfminimizer_conjugate_fr
is not defined in cdtm_ext.so
, it is referenced in cdtm_ext.so
but undefined, that is what U
stands for. You need to link to the library in your case gsl
to define that symbol.
See http://www.boost.org/doc/libs/1_46_1/doc/html/bbv2/tutorial.html#bbv2.tutorial.prebuilt for how to link libraries with bjam.