简体   繁体   English

未定义的升压 python 符号:boost::python::detail::init_module

[英]Undefined boost python symbol: boost::python::detail::init_module

I get an undefined symbol error when trying to import an extension compiled with boost python, and the symbol is one that should be included in the boost library.尝试导入使用 boost python 编译的扩展时出现未定义符号错误,该符号应该包含在 boost 库中。

I am using Boost 1.46.1, Python 3.1.2, and GCC 4.4.5.我正在使用 Boost 1.46.1、Python 3.1.2 和 GCC 4.4.5。

I've built boost using:我使用以下方法构建了 boost:

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

I then compiled the following trivial Boost Python library:然后我编译了以下简单的 Boost Python 库:

#include <boost/python.hpp>

struct mystruct {
    int i;
};

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

using the command:使用命令:

$ g++ -shared question.cpp -I/usr/include/python3.1 -lboost_python3 -lpython3.1 -otest.so

which succeeds without error.成功没有错误。

I then try to run it in python, but it can't seem to find the init_module function boost python is supposed to provide:然后我尝试在 python 中运行它,但它似乎找不到 init_module function boost python 应该提供:

$ 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 reports the following: ldd 报告以下内容:

$ ldd -r test.so
    linux-gate.so.1 =>  (0x00ab3000)
    libboost_python3.so.1.46.1 => /usr/local/lib/libboost_python3.so.1.46.1 (0x002fe000)
    libpython3.1.so.1.0 => /usr/lib/libpython3.1.so.1.0 (0x005dc000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x001f8000)
    libm.so.6 => /lib/libm.so.6 (0x00110000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00424000)
    libc.so.6 => /lib/libc.so.6 (0x00886000)
    libutil.so.1 => /lib/libutil.so.1 (0x00e13000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00136000)
    libdl.so.2 => /lib/libdl.so.2 (0x00349000)
    librt.so.1 => /lib/librt.so.1 (0x00150000)
    libssl.so.0.9.8 => /lib/libssl.so.0.9.8 (0x00553000)
    libcrypto.so.0.9.8 => /lib/libcrypto.so.0.9.8 (0x00ab4000)
    libffi.so.5 => /usr/lib/libffi.so.5 (0x00159000)
    libz.so.1 => /lib/libz.so.1 (0x00160000)
    libexpat.so.1 => /lib/libexpat.so.1 (0x00175000)
    /lib/ld-linux.so.2 (0x00495000)
undefined symbol: _ZN5boost6python6detail11init_moduleEPKcPFvvE (./test.so)

EDIT:编辑:

nm confirms that /usr/local/lib/libboost_python3.so.1.46.1 does indeed include init_module, yet the error persists: nm确认/usr/local/lib/libboost_python3.so.1.46.1确实包含 init_module,但错误仍然存在:

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

The undefined symbol is未定义的符号是

boost::python::detail::init_module(char const*, void (*)())

not不是

boost::python::detail::init_module(PyModuleDef&, void (*)())

on http://www.boost.org/doc/libs/1_46_1/boost/python/module_init.hpp I see that the method signature has changed to the latter one in Python 3.http://www.boost.org/doc/libs/1_46_1/boost/python/module_init.hpp我看到方法签名已更改为 Python 3 中的后者。

You should make sure that PY_VERSION_HEX is set correctly when the boost python headers are processed.在处理 boost python 标头时,您应该确保PY_VERSION_HEX设置正确。

On my system, I see that this is eg defined in /usr/include/python3.1/patchlevel.h (but I had to install the python 3.1 development package first)在我的系统上,我看到这是在/usr/include/python3.1/patchlevel.h中定义的(但我必须先安装 python 3.1开发package)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM