繁体   English   中英

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

[英]boost python library linking issue — undefined symbol

我正在使用为python3构建的boost-python来公开一个简单的hello-world程序。 可以在这里找到示例: https : //github.com/TNG/boost-python-examples/blob/master/01-HelloWorld/hello.cpp

我运行以下命令来获取共享库:

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

之后,我运行python3 -c 'import hello'命令,并得到以下错误:Traceback(最近一次调用为last):

文件“”,第1行,位于ImportError中:hello.so:未定义符号:_ZTIN5boost6python7objects21py_function_impl_baseE

我部分理解这个问题可能是因为我的boost-python安装可能是为其他python版本(例如python2.7)构建的。 当我运行命令时:

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

有三个.so文件:

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

如何解决这个问题?

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

安装miniconda可能是您的选择。 https://conda.io/miniconda.html

这将提供一个完整的,隔离的python环境。 然后您可以conda install boost

我已经在系统上对此进行了测试,并且效果很好。 我从http://www.shocksolution.com/python-basics-tutorials-and-examples/linking-python-and-c-with-boostpython/修改了Makefile

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

暂无
暂无

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

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