2

I am doing some tiny work with Qt on Mac. I need to call a python function in my main function. But when I try to call Py_initialize() as everyone said, compiler throws a error like this:

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"

My code is trivial and there should not be anything weird about this. Here it is:

// 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();
}

When I comment the Py_initalize() line, everything works fine. I figure that this is something to do with OSx. But I really don't know how to fix this thing. Help needed.

alvinzoo
  • 493
  • 2
  • 8
  • 17

1 Answers1

2

Change your include line to this

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

using namespace std;


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

Py_Initialize();
developer_hatch
  • 15,898
  • 3
  • 42
  • 75