I compiled and installed boost 1.46.1 from source recently using:

$ ./bootstrap.sh --with-python-version=3.1
$ sudo ./bjam -j4 install

I then created the following trivial python extension:

#include <boost/python.hpp>

struct mystruct {
    int i;
};

BOOST_PYTHON_MODULE(test) {
    using namespace boost::python;
    class_<mystruct>("Mystruct")
        .def_readwrite("i", &mystruct::i)
        ;
}

and compiled and ran it, but got an undefined symbol error:

$ g++ -shared question.cpp -I/usr/include/python3.1 -lboost_python3 -otest.so
$ python3
Python 3.1.2 (release31-maint, Sep 17 2010, 20:34:23)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./test.so: undefined symbol: _ZN5boost6python6detail11init_moduleEPKcPFvvE

ldd confirms the missing symbol:

$ ldd -r test.so
linux-gate.so.1 =>  (0x00221000)
libboost_python3.so.1.46.1 => /usr/local/lib/libboost_python3.so.1.46.1 (0x00a3d000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0022b000)
libm.so.6 => /lib/libm.so.6 (0x00960000)
libc.so.6 => /lib/libc.so.6 (0x00316000)
libutil.so.1 => /lib/libutil.so.1 (0x004b8000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00cf2000)
libdl.so.2 => /lib/libdl.so.2 (0x00be4000)
librt.so.1 => /lib/librt.so.1 (0x005d3000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00489000)
/lib/ld-linux.so.2 (0x00fd5000)
undefined symbol: PyExc_ImportError (/usr/local/lib/libboost_python3.so.1.46.1)
undefined symbol: PyProperty_Type (/usr/local/lib/libboost_python3.so.1.46.1)
... snip ...
undefined symbol: _ZN5boost6python6detail11init_moduleEPKcPFvvE (./test.so)
undefined symbol: _Py_NoneStruct (./test.so)
undefined symbol: PyLong_FromLong (./test.so)
undefined symbol: PyLong_Type (./test.so)

However nm confirms that the symbol exists in /usr/local/lib/libboost_python3.so.1.46.1:

$ nm /usr/local/lib/libboost_python3.so.1.46.1 | c++filt | grep init_module
00031a00 T boost::python::detail::init_module(PyModuleDef&, void (*)())

I've tried running ldconfig to update the library cache, as well as compiling the extension with -lpython3.1, but no luck.

Ideas appreciated,

Vivek