0

I am facing errors on below code even after trying the solutions obtained by online search. Anyone please enlighten me. appreciate the help. I was using Eclipse with MinGW GCC as Toochains

myPython\Debug/../src/myPython.cpp:14: undefined reference to `_imp__Py_Initialize'

#include <iostream>
using namespace std;
#include "c:\python27\include\Python.h"

int main() {
Py_Initialize();
Py_Finalize();
return 0;
}
user10293779
  • 103
  • 6

1 Answers1

1

I was looking a solution for same problem, and finally found this link which was usefull for me. Please see the first response, not the last one, cause I got successfully installed mingw64 and running pyhon 64 bit version, (or in your case if you use Mingw32 bit version, you must download python 32 bit version also). Just don't forget edit Windows PATH environment variable to take account your mingw\bin location, then you must configure into Eclipse which libray you use and location following these steps:

Project->Properties->C/C++ Build->Settings->MinGW C++ Linker Libraries

In my case I use python 3.7 so in Libraries I put 'python37' without '-l', and in Library search path, the arbitrary path of python37.dll location, please see below. Then after successfull compiling I try o run the program, but the executable could not find the dll, so I simply copied the dll into same directory and finally got working (may be this is not the propoer solution but It works)

My config

I guess you'll like to use C++ & Python using OOP, so I leave you this link also that explains very well Creating a python object in C++ and calling its method

byteptr
  • 7
  • 1
  • Thank you for advice above. My python2.7 is 64-bit, MinGW is at c:\MinGW that works for 32 and 64 bit. i just added " c:\MinGW\bin" in Environment|User Variable|Path – user10293779 Dec 23 '19 at 08:39
  • In Project->Properties->C/C++ Build->Settings->MinGW C++ Linker Libraries, I added 'C:\Python27\Lib' in 'Library (-l) but cannot add 'Library search path (-L) because no 'Python' under 'C:\MinGW\'. – user10293779 Dec 23 '19 at 09:10
  • With changes mentioned above, now the error message in eclipse is: c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lC:\Python27\lib – user10293779 Dec 23 '19 at 09:11
  • By the way, i also followed the instruction in the first link "this" to download the zip file and copy it at my c++ project folder. – user10293779 Dec 23 '19 at 09:21
  • "but cannot add 'Library search path (-L) because no 'Python' under 'C:\MinGW\'." yes, of course, the python dll path is an arbitrary path, I copied into the same folder so migth this lead to confusion... As eclipse concerns In the past I have had also some issues with files not found even if the paths were correct... I didn't remember how I solved it, but I passed through reinstalling and rebooting. – byteptr Dec 24 '19 at 19:03