0

i have included the path to python.h(C:\Users\vinay\AppData\Local\Programs\Python\Python37-32\include) file and gave the library path of the project to "C:\Users\AppData\Local\Programs\Python\Python37-32\Lib" and my code is as pasted below:-

    #include <iostream>
    #include <Python.h>
    using namespace std;

    int main(int argc, char **argv)
    {
        PyObject *pInt;
        Py_Initialize();
        PyRun_SimpleString("print('Hello world from embedded python!!!\n')");
        Py_Finalize();
        cout<<"now i am finally out of the python"<<endl;
        return 0;

    }

when i compile the program there is no error but when i build the project i get the following erros

C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:8: undefined reference to `_imp__Py_Initialize'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:9: undefined reference to `_imp__PyRun_SimpleStringFlags'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:10: undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Cpp_in_python] Error 1
mingw32-make.exe: *** [All] Error 2
Cpp_in_python.mk:78: recipe for target 'Debug/Cpp_in_python' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/vinay/Documents/CppWorkspace/Cpp_in_python'
Makefile:4: recipe for target 'All' failed
====4 errors, 0 warnings====
JRajan
  • 672
  • 4
  • 19
Vinay
  • 81
  • 1
  • 8
  • Did you check the steps mentioned in https://stackoverflow.com/questions/52264686/embedding-python-undefined-reference-to-imp-py-initialize? It might throw some light on your current issue. – JRajan Nov 28 '19 at 07:29
  • yes i have included the python libs directory to my library path of the project, however i haven't tried the second answer though! where exactly do i add this line ? "g++ TestEmbedding.cpp `python3-config --includes` -o TestEmbedding" even if i have to check if this works – Vinay Nov 28 '19 at 07:39
  • Which command are you using for building your project? Is it an IDE or from commandline? – JRajan Nov 28 '19 at 07:45
  • should i give a pre build command? and where do i get python3-config file? i cannot find it in my pythons directory i am using an IDE called codeLite – Vinay Nov 28 '19 at 10:04
  • I haven't heard of this IDE before today. Maybe someone more familiar with this can help you out with setting up the pre-build command. Also, this might be a python2 vs python3 incompatibility issue as suggested in the linked answer. – JRajan Nov 28 '19 at 10:59
  • i figured how to set up the pre-build command what should be the pre-build command? i gave my pre-build command to be "g++ main.cpp 'python3-config --includes' -o main" is this correct? since my only cpp file is main.cpp – Vinay Nov 28 '19 at 11:07
  • Yeah looks good to me. But I'm not sure if it would solve your issue if it is python2/3 compatibility thing. – JRajan Nov 28 '19 at 11:14
  • any idea about how i can fix this? – Vinay Nov 29 '19 at 10:43

0 Answers0