我正在使用为 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'
命令,我收到以下错误:
追溯(最近一次通话最后一次):
File "", line 1, in ImportError: hello.so: undefined symbol: _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
关于python - boost python 库链接问题 -- undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45576378/