簡體   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