简体   繁体   English

提升python库链接问题-未定义符号

[英]boost python library linking issue — undefined symbol

I am using boost-python built for python3 to expose a simple hello-world program. 我正在使用为python3构建的boost-python来公开一个简单的hello-world程序。 The example can be found here : https://github.com/TNG/boost-python-examples/blob/master/01-HelloWorld/hello.cpp 可以在这里找到示例: https : //github.com/TNG/boost-python-examples/blob/master/01-HelloWorld/hello.cpp

I ran the following commands to get the shared object: 我运行以下命令来获取共享库:

g++ -fPIC -c -I/usr/include/python3.4m -I/usr/include/python3.4m  -Wno-unused-result -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -L/usr/lib/x86_64-linux-gnu/libboost_python-py34 hello.cpp

g++ -shared hello.o -o hello.so

After this, I run the python3 -c 'import hello' command and I get the following error: Traceback (most recent call last): 之后,我运行python3 -c 'import hello'命令,并得到以下错误:Traceback(最近一次调用为last):

File "", line 1, in ImportError: hello.so: undefined symbol: _ZTIN5boost6python7objects21py_function_impl_baseE 文件“”,第1行,位于ImportError中:hello.so:未定义符号:_ZTIN5boost6python7objects21py_function_impl_baseE

I partly understand this issue may be because my boost-python installation may be built for an alternative python version (for instance python2.7). 我部分理解这个问题可能是因为我的boost-python安装可能是为其他python版本(例如python2.7)构建的。 When I run the command: 当我运行命令时:

ls /usr/lib/x86_64-linux-gnu/libboost_python*.so

There are three .so files: 有三个.so文件:

1. libboost_python-py27.so
2. libboost_python-py34.so
3. libboost_python.so

How can this issue be circumvented? 如何解决这个问题?

使用pkg-config检索boost库的ldflags和cflags

Installing miniconda might be an option for you. 安装miniconda可能是您的选择。 https://conda.io/miniconda.html https://conda.io/miniconda.html

This will provide a complete, isolated, python environment. 这将提供一个完整的,隔离的python环境。 You can then conda install boost 然后您可以conda install boost

I've tested this on my system and it worked well. 我已经在系统上对此进行了测试,并且效果很好。 I modified the Makefile from http://www.shocksolution.com/python-basics-tutorials-and-examples/linking-python-and-c-with-boostpython/ 我从http://www.shocksolution.com/python-basics-tutorials-and-examples/linking-python-and-c-with-boostpython/修改了Makefile

My Makefile can be found here: https://github.com/grelleum/boost-python-with-anaconda 我的Makefile可以在这里找到: https : //github.com/grelleum/boost-python-with-anaconda

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

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