【发布时间】:2015-05-07 18:18:57
【问题描述】:
我在开始使用 Boost 的 python 库时遇到了问题。我的代码是
#include <boost/python.hpp>
#include <Python.h>
namespace python=boost::python;
int main(int argc, char const *argv[])
{
Py_Initialize();
python::dict global;
return 0;
}
我尝试了很多,最接近工作程序的是 boost 的链接错误:
$ gcc -c $(python2.7-config --cflags) bpt.cpp
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
$ gcc bpt.o $(python2.7-config --ldflags) -o bpt
bpt.o: In Funktion `dict':
/usr/include/boost/python/dict.hpp:89: Nicht definierter Verweis auf `boost::python::detail::dict_base::dict_base()'
collect2: error: ld returned 1 exit status
我通过 apt-get (libboost-all-dev) 安装了 Boost,所以 gcc 应该可以找到它,不是吗?我知道 bjam 是使用 boost::python 编译程序的首选方式,但由于我只是想要 python 解释器用于绘图,我不想启动 Jamfile 和 boost-build.jam 等等。那么我需要做什么才能链接到图书馆呢?
【问题讨论】:
-
Boost.Python 不仅仅是标题,您还需要链接到库。尝试将
-lboost_python添加到 gcc 命令行。 -
谢谢,那是我丢失的标志。你能说明一下我自己在哪里可以找到的吗?
-
据我所知,CMake 也可以为您做到这一点。见stackoverflow.com/a/5238644/147808。
-
@Praetorian 为什么你的答案在评论中?
-
它应该列在 Boost.Python 文档的某个地方(希望 Boost.Python 在文档方面不是最好的)