python - boost python 库链接问题 -- undefined symbol

标签 python c++ python-3.x ubuntu boost

我正在使用为 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/

相关文章:

c++ - 从 char 在 C++ 中创建校验和

c++ - 你能向我解释一下变形方法的这一部分吗(使用 OpenCV、C++ 和 Qt)?

python - 不明白为什么这段代码会引发 EOF 错误

python - 事务管理器恢复/回滚上次提交

python - 是否可以使用 App Engine 生成并返回 ZIP 文件?

python - Selenium Python Headless Webdriver (PhantomJS) 不工作

python - 为什么 flake8 对于我在 "undefined name" block 中定义的内容说 `as`?

c# - 为什么 C++ fseek/fread 的性能是 C# FileStream 的 Seek/Read 的数倍

python - python 中的数学公式不起作用

django - 'str' 的 Pylint Django 模型实例没有成员