简体   繁体   English

使用boost :: python链接错误

[英]Linking error with boost::python

I have a problem getting started with Boost's python library. 我开始使用Boost的python库时遇到了问题。 My code is 我的代码是

#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;
}

I tried a lot and the closest I get to a working program is a linking error with boost: 我尝试了很多,最接近工作程序的是与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

I installed Boost through apt-get (libboost-all-dev) so gcc should find it, shouldn't it? 我通过apt-get(libboost-all-dev)安装了Boost,所以gcc应该找到它,不应该吗? I know that bjam is the preferred way to compile programs using boost::python, but as i just wanted the python interpreter for plotting purposes, i don't wanted to start up with Jamfile and boost-build.jam and so on. 我知道bjam是使用boost :: python编译程序的首选方法,但由于我只是想将python解释器用于绘图目的,我不想启动Jamfile和boost-build.jam等等。 So what do I have to do to link against the library? 那么我需要做些什么来链接库?

As Praetorian say you need to link with the proper library. 正如Praetorian所说,你需要与正确的图书馆联系。

Add -lboost_python to the command line: -lboost_python添加到命令行:

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

Unfortunately the boost-python documentation isn't very clear on the subject, but there is a general instruction for boost on how to link with their libraries: how to link to a boost library . 不幸的是,boost-python文档在这个主题上并不是很清楚,但是有一个关于如何链接到它们的库的一般指令: 如何链接到boost库

Linking is necessary whenever you use a library that isn't header only. 只要您使用的库不是标题库,就必须进行链接。

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

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