1
我在Mac上用Qt做了一些小小的工作。我需要在我的主函數中調用一個python函數。但是,當我嘗試調用Py_initialize()爲大家都說,編譯器將拋出一個錯誤這樣的:Qt:嘗試在qt中使用python.h時未定義的符號
Undefined symbols for architecture x86_64:
"_Py_Initialize", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make: *** [video.app/Contents/MacOS/video] Error 1
07:48:07: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project video (kit: Desktop Qt 5.8.0
clang 64bit)
When executing step "Make"
我的代碼是微不足道,不應該有什麼奇怪的這一點。這是它:
// bunch of headers
#include <python2.7/Python.h>
using namespace std;
int main(int argc, char *argv[])
{
Py_Initialize();
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:///main.qml")));
QObject *object = component.create();
QObject *mainForm = object->findChild<QObject*>("mainForm");
SignalNexus sn;
QObject::connect(mainForm, SIGNAL(populateToken(QString)), &sn, SLOT(pushToPipe(QString)));
QObject::connect(&sn, SIGNAL(populateResult(QVariant, QVariant)), mainForm, SLOT(handleResult(QVariant, QVariant)));
return app.exec();
}
當我評論Py_initalize()線,一切工作正常。我認爲這與OSx有關。但我真的不知道如何解決這個問題。需要幫助。
酷,它的工作原理。你能給我一個簡單的解釋嗎?謝謝! – alvinzoo
當然可以! Python已經是Mac OS X上的一個框架!所以你實際上在C裏面不需要做任何事情:) –
如果你想從比我更專業的人那裏得到更好的解釋,你可以在這裏看到更多http://stackoverflow.com/questions/16454129/python-h-header -file-missing-on-mac-os-x-10-6 –