1
我想開始使用boost:蟒蛇在我的C++程序中嵌入Python,但我已經有這個簡單的代碼問題:未定義參考:pyton程序
#include <boost/python.hpp> //boost libraries
#include <Python.h> //python libraries
using namespace boost::python;
int main()
{
Py_Initialize();
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__");
return 0;
}
我剛開始解釋和導入主模塊,但編譯器已經有問題是:
/home/i7941878/Code/pythonTest/main.cpp:-1: error: undefined reference to `boost::python::detail::str_base::str_base(char const*)'
/home/i7941878/Code/pythonTest/main.cpp:-1: error: undefined reference to `boost::python::import(boost::python::str)'
/home/i7941878/Code/pythonTest/main.cpp:-1: error: undefined reference to `boost::python::api::getattr(boost::python::api::object const&, char const*)'
我沒有線索爲什麼我收到那些錯誤。我非常確定提升:Python構建正確。
任何人都能照亮我嗎?
我正在使用QT創建器來編譯和編譯。 如果我編譯使用G ++與-I/usr/include -I/usr/include/python2.6 main.cpp
我得到:
/tmp/ccI8x97b.o: In function `main':
main.cpp:(.text+0xc): undefined reference to `Py_Initialize'
main.cpp:(.text+0x30): undefined reference to `boost::python::import(boost::python::str)'
/tmp/ccI8x97b.o: In function `boost::python::api::object::object()':
main.cpp:(.text._ZN5boost6python3api6objectC2Ev[_ZN5boost6python3api6objectC5Ev]+0xd): undefined reference to `_Py_NoneStruct'
/tmp/ccI8x97b.o: In function `boost::python::api::const_attribute_policies::get(boost::python::api::object const&, char const*)':
main.cpp:(.text._ZN5boost6python3api24const_attribute_policies3getERKNS1_6objectEPKc[boost::python::api::const_attribute_policies::get(boost::python::api::object const&, char const*)]+0x26): undefined reference to `boost::python::api::getattr(boost::python::api::object const&, char const*)'
/tmp/ccI8x97b.o: In function `boost::python::str::str(char const*)':
main.cpp:(.text._ZN5boost6python3strC2EPKc[_ZN5boost6python3strC5EPKc]+0x1f): undefined reference to `boost::python::detail::str_base::str_base(char const*)'
collect2: ld returned 1 exit status
我編碼和用qt創作者編譯,在pro文件我有 'INCLUDEPATH + =在/ usr /包括/ python2.6的/' 這是路徑Python和 'INCLUDEPATH + =/usr/include /' 這是boost庫的路徑 – leoncvlt
@MegaLeon包含路徑不是問題。你還需要鏈接這些庫,你顯然沒有這樣做。 –
的確,我不得不在.pro文件中導入庫。我希望包括頭文件就夠了。謝謝! – leoncvlt