[Python] Unable to use static library of boost.python due to undefined symbols

Hi folks,
I'm trying to build a python extension with statically linked
libboost_python on Linux.
I built boost_python with
./bjam -q --layout=system --with-python toolset=gcc variant=release
link=static threading=multi runtime-link=static
which results in a 700kb libboost_python.a
Then I try to build the hello world example located at
/libs/python/example/tutorial
but I fail, because their remain undefined symbols, despite the fact I
did define BOOST_PYTHON_STATIC_LIB.
Heres what I did:
$ cat hello.cpp
// Copyright Joel de Guzman 2002-2004. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// Hello World Example from the tutorial
// [Joel de Guzman 10/9/2002]
#include
import libhello Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: ./libhello.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
The example works marvellous when using the shared lib of boost_python, but it has to be a static build for me. I found a mailing list entry from 2002 mentioning the static build of boost.python was broken, but that is for sure fixed by now, isn't it? Regards, Philipp

Philipp Münzel wrote:
$ g++ -I/usr/local/include -I/usr/include/python -DBOOST_PYTHON_STATIC_LIB -fpic -c -o hello.o hello.cpp $ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python -fpic -o libhello.so hello.o
In general, static libraries should be specified on the command line after the object files that use symbols in them. Do things work better if you move -lboost_python to the end? - Volodya

Vladimir Prus
In general, static libraries should be specified on the command line
after
the object files that use symbols in them. Do things work better if you move -lboost_python to the end?
Oh, seriously: HEADDESK! Big thank you! I had to recompile with bjam cxxflags=-fPIC though, otherwise the link would fail. One question remains: The next step in the tutorial is to:
import hello_ext print hello.greet() hello, world
But I get:
import hello_ext hello.greet() Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'hello' is not defined print hello_ext.greet() hello, world
Why is my module named hello_ext, when in the tutorial it says its just hello? Regards, Philipp
- Volodya
_______________________________________________ Boost-users mailing list Boost-users <at> lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Philipp Münzel
-
Vladimir Prus