简体   繁体   English

Ubuntu 15.04上libboost_python-py34的链接器错误

[英]Linker error with libboost_python-py34 on Ubuntu 15.04

I must be making some simple mistake trying to use boost-python on Ubuntu Linux 15.04 (Vivid Vervet), with the libboost-python1.55-dev package installed. 在安装了libboost-python1.55-dev软件包的Ubuntu Linux 15.04(Vivid Vervet)上尝试使用boost-python时,我肯定犯了一个简单的错误。

I'm trying to build a simple test file like so: 我正在尝试构建一个像这样的简单测试文件:

$ g++ -o conftest -Wall -I/usr/include/python3.4m -I/usr/include/x86_64-linux-gnu/python3.4m  -L/usr/lib/x86_64-linux-gnu -lboost_python-py34 -lpython3.4m conftest.cc

But that gives me this linker error: 但这给了我这个链接器错误:

/tmp/ccxkW5XR.o: In function `PyInit_test':
conftest.cc:(.text+0x7e): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
collect2: error: ld returned 1 exit status

But that symbol really does seem to exist: 但是这个符号确实确实存在:

$ nm -D --demangle /usr/lib/x86_64-linux-gnu/libboost_python-py34.so | grep "init_module"
0000000000033ac0 T boost::python::detail::init_module(PyModuleDef&, void (*)())

This is the very simple test code that I'm building, based on a config test used by the AX_BOOST_PYTHON autoconf macro: 这是我正在构建的非常简单的测试代码,基于AX_BOOST_PYTHON autoconf宏使用的配置测试:

#include <boost/python/module.hpp>

BOOST_PYTHON_MODULE(test) { throw "Boost::Python test."; }

int
main ()
{
  return 0;
}

Can anyone see what I'm doing wrong? 谁能看到我在做什么错?

The first thing that stuck out to me in your compiler invocation is that you've listed the libraries before the source file that uses them on the command line. 在编译器调用中出现的第一件事是,您已在命令行中在使用库的源文件之前列出了这些库。

This will usually work anyway with shared libraries, but isn't strictly correct. 无论如何,这通常都可以与共享库一起使用,但并非严格正确。 For instance, it'll break if you're using static libraris, since only the objects from the archive needed to satisfy symbols from things earlier in the command line are included. 例如,如果您使用静态库,它将中断,因为仅包含档案库中满足命令行前面内容符号所需的对象。 But it seems to make a difference here, even though we're using shared libraries: 但这似乎有所不同,即使我们使用共享库也是如此:

$ g++ -o conftest -Wall -I/usr/include/python3.4m -I/usr/include/x86_64-linux-gnu/python3.4m  -L/usr/lib/x86_64-linux-gnu -lboost_python-py34 -lpython3.4m conftest.cc
/tmp/ccj8Znlk.o: In function `PyInit_test':
conftest.cc:(.text+0x7e): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
collect2: error: ld returned 1 exit status
$ g++ -o conftest -Wall -I/usr/include/python3.4m -I/usr/include/x86_64-linux-gnu/python3.4m  -L/usr/lib/x86_64-linux-gnu conftest.cc -lboost_python-py34 -lpython3.4m
$ ldd conftest | grep python
    libboost_python-py34.so.1.55.0 => /usr/lib/x86_64-linux-gnu/libboost_python-py34.so.1.55.0 (0x00007f6291003000)
    libpython3.4m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.4m.so.1.0 (0x00007f62909c2000)

The second g++ invocation succeeds and produces a correctly linked executable. 第二次g++调用成功,并生成正确链接的可执行文件。

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

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