gpt4 book ai didi

python - Qt:尝试在 qt 中使用 python.h 时 undefined symbol

转载 作者:行者123 更新时间:2023-11-30 05:13:42 25 4
gpt4 key购买 nike

我正在 Mac 上使用 Qt 做一些小的工作。我需要在我的主函数中调用一个 python 函数。但是当我像大家所说的那样尝试调用 Py_initialize() 时,编译器会抛出这样的错误:

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 有关。但我真的不知道如何解决这个问题。需要帮助。

最佳答案

将您的包含行更改为此

// bunch of headers
#include <Python/Python.h>

using namespace std;


int main(int argc, char *argv[])
{

Py_Initialize();

关于python - Qt:尝试在 qt 中使用 python.h 时 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43815266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com