1

How to fix"temp\ccSZ9gCR.o....undefined reference to `_imp__Py_Initialize' Error?

I use MinGW to compile a c++ file, which includes <python.h>.

g++ -Ic:\ProgramData\Anaconda3\include test.cpp

It returns the error temp\ccSZ9gCR.o....undefined reference to `_imp__Py_Initialize'

How can I fix it?

p.s. ,I want to embed python in C++.At first,I guess I should use -I -L to add some directories to be included in. I changed the g++ comand as this:

    g++ -Ic:\ProgramData\Anaconda3\include -Lc:\ProgramData\Anaconda3\libs test.cpp

In libs directory, there are python3.lib and python37.lib files. But I still got the same error result.

xinranhou
  • 11
  • 1
  • 6
  • 2
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – melpomene Feb 16 '19 at 12:40
  • I solved this problem by reference to https://stackoverflow.com/questions/6731100/link-to-python-with-mingw 1)Run gendef /c/windows/system32/python32.dll 2)Run dlltool -D python32.dll -d python32.def -l libpython32.a 3)Copy libpython32.a to your ./python32/libs directory. – xinranhou Feb 21 '19 at 01:26

0 Answers0