I'm trying to embed Python within my C++ project (Qt5). My project looks like this:
python_test.pro:
QT += core
QT -= gui
TARGET = python_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\Tools\Python\Python35_64\include
LIBS += -LC:\Tools\Python\Python35_64\ -lpython3
main.cpp:
#include <Python.h>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
Py_Finalize();
return a.exec();
}
When compiling I get a linker error telling me this: main.cpp:-1: Error: undefined reference to `__imp_PyRun_SimpleStringFlags'.
The funny thing is that Py_Initialize() and Py_Finalize() can be found. I read something about the define Py_LIMITED_API which hides the function PyRun_SimpleStringFlags. But I don't get it.
How am I supposed to run a Python script/file/string without these functions being available within the C API?
Setup:
- Win7 Prof 64 bit
- Qt 5.5.1
- g++.exe (Rev1, Built by MSYS2 project) 5.3.0
- Python 3.5.1 64-bit (prebuilt from https://www.python.org/downloads/release)/python-351/)
-lpython35and not-lpython3.pythonqt(pythonqt.sourceforge.net) it's a really powerful way to bind Qt applications and python (it's PyQt the other way round)