Hello I am new at programming and I would like to be able to execute python code from c++ app.
I have 0 knoledge on c++, I only know python. I am trying to follow this tutorial https://www.codeproject.com/Articles/820116/Embedding-Python-program-in-a-C-Cplusplus-code but because I dont know c++ I find it hard to follow.
I am using windows 10. I have manage to install minGW as my compiler.
This is the c++ code called run_py.cpp:
#include <stdio.h>
#include <conio.h>
#include <Python.h>
int main()
{
PyObject* pInt;
Py_Initialize();
PyRun_SimpleString("print('Hello World from Embedded Python!!!')");
Py_Finalize();
printf("\nPress any key to exit...\n");
if(!_getch()) _getch();
return 0;
}
I have already installed the python dev tools so I have Python.h already. I am trying to compile my cpp file using this command from the windows terminal.
g++ -I C:\Users\...\Python39\include run_py.cpp -L C:\Users\...\Python39\libs -o run_py.exe
But it gives me this error:
C:\Users\...\AppData\Local\Temp\cceaTqLQ.o:run_py.cpp:(.text+0xf): undefined reference to `_imp__Py_Initialize'
C:\Users\...\AppData\Local\Temp\cceaTqLQ.o:run_py.cpp:(.text+0x25): undefined reference to `_imp__PyRun_SimpleStringFlags'
C:\Users\...\AppData\Local\Temp\cceaTqLQ.o:run_py.cpp:(.text+0x2c): undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
How can I fix this??