繁体   English   中英

使用boost :: python链接错误

[英]Linking error with boost::python

我开始使用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等等。 那么我需要做些什么来链接库?

正如Praetorian所说,你需要与正确的图书馆联系。

-lboost_python添加到命令行:

gcc bpt.o -lboost_python $(python2.7-config --ldflags) -o bpt

不幸的是,boost-python文档在这个主题上并不是很清楚,但是有一个关于如何链接到它们的库的一般指令: 如何链接到boost库

只要您使用的库不是标题库,就必须进行链接。

暂无
暂无

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

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