Python: undefined reference to `_imp __Py_InitModule4'

I'm trying to do a debug build of the Rabbyt library using mingw's gcc to run with my MSVC built python26_d.. I got a lot of undefined references which caused me to create libpython26_d.a, however one of the undefined references remains. Googling gives me:

http://www.techlists.org/archives/programming/pythonlist/2003-03/msg01035.shtml

But -rdynamic doesn't help.

e:\MinGW/bin\gcc.exe -mno-cygwin -mdll -O -Wall -g -IE:\code\python\python\py26\
include -IE:\code\python\python\py26\PC -c rabbyt/rabbyt._rabbyt.c -o build\temp
.win32-2.6-pydebug\Debug\rabbyt\rabbyt._rabbyt.o -O3 -fno-strict-aliasing
rabbyt/rabbyt._rabbyt.c:1351: warning: '__Pyx_SetItemInt' defined but not used
writing build\temp.win32-2.6-pydebug\Debug\rabbyt\_rabbyt_d.def

e:\MinGW/bin\gcc.exe -mno-cygwin -shared -g build\temp.win32-2.6-pydebug\Debug\r
abbyt\rabbyt._rabbyt.o build\temp.win32-2.6-pydebug\Debug\rabbyt\_rabbyt_d.def -
LE:\code\python\python\py26\libs -LE:\code\python\python\py26\PCbuild -lopengl32
 -lglu32 -lpython26_d -lmsvcr90 -o build\lib.win32-2.6-pydebug\rabbyt\_rabbyt_d.
pyd
build\temp.win32-2.6-pydebug\Debug\rabbyt\rabbyt._rabbyt.o: In function `init_ra
bbyt':

E:/code/python/rabbyt/rabbyt/rabbyt._rabbyt.c:1121: undefined reference to `_imp
__Py_InitModule4'

If anyone comes across this same error message, but in a different situation: try to add -D MS_WIN64 to your command line, it worked for me!

Python Module Build On Windows Fails · Issue #224 · miniupnp , Re: [Mingw-w64-public] 64bit Python bindings for libftdi1-1.0 with MinGW-w64 undefined reference to `__imp_Py_InitModule4' collect2.exe: error: ld returned 1 it back to Py_InitModule4 to get the Python binding build successfully. line 26​, in swig_import_helper _mod = imp.load_module('_ftdi1', fp,  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

In the file C:\Python27\Lib\distutils\cygwinccompiler.py, which contains the MinGW compiler settings, find the Mingw32CCompiler class:

self.set_executables(compiler='gcc -O -Wall',
    compiler_so='gcc -mdll -O -Wall',
    compiler_cxx='g++ -O -Wall',
    linker_exe='gcc ',
    linker_so='%s %s %s'
        % (self.linker_dll, shared_option,
        entry_point))

and add -D MS_WIN64 to the compiler_so argument:

compiler_so='gcc -mdll -O -Wall -D MS_WIN64'

MinGW-w64, c:\documents and settings\mico\my documents\spammodule.o( text+0xa3):​spammodule.c: undefined reference to `_imp__Py_InitModule4' c:\documents and  Can not install pyton-axolotl during yowsup install, undefined reference to _imp__Py_InitModule4 #1274

I have seen this if you try to mix object code compiled for debugging (_DEBUG macro is defined) with non-debug objects (_DEBUG is not defined).

There is a line in the python core code that #defines Py_InitModule4 to another name (Py_InitModule4TraceRefs) to trigger a "link-time error" (!sic) if you mix objects.

Make sure you link against a python debug library when you compile for debugging and vice-versa.

Making python extension in Windows, My installations of Cygwin and MinGW gcc contradicted each other. I uninstalled both of them and installed MinGW and cygwin without gcc, and this solved the  There is a mechanism in Python to prevent linking a module against the wrong version of the library. The Py_InitModule4 function is renamed to Py_InitModule4_64 (via a macro) when the library / module is compiled for a 64-bit architecture (see modsupport.h) :

I just solved this problem by adding the compiler flag -DPy_TRACE_DEFS. In my case I was trying to build debug versions of SIP/PyQt.

The error can occur when the debug version of Python is compiled with the Py_TRACE_DEFS option switched on. This causes the resulting python2x_d library to contain the function Py_InitModule4TraceRefs instead of Py_InitModule4 that the compiler is looking for (amongst other changes). Switching the option on for the project you are building ensures the code produced is compatible, and that the correct version of Py_InitModule4 is found.

More information on Py_TRACE_DEFS can be found in Misc/SpecialBuilds.txt in the Python source folder or here.

Undefined references message when compiling, and settings\mico\my documents\spammodule.o(=0D text+0xa3):spammodule.​c: undefined reference to `_imp__Py_InitModule4' =0D  [nuitka-dev] Re: undefined reference to `__imp_Py_InitModule4_64' Let me know about that "python.exe" thing from above. I would gladly see that fixed too.

My Cygwin and MinGW gcc installs were conflicting with each other. I deleted them both and the installed MinGW and cygwin without gcc and that solved the problem.

Python: undefined reference to `_imp __Py_InitModule4 '- python, Я пробую компиляцию оболочки кода C++ в python 2.7 с помощью SWIG. undefined reference to `_imp__PyString_AsString' Au niveau de to `_imp__​Py_InitModule4' test8_wrap.o:test8_wrap.cxx:(.text+0x2a18): undefined reference to  libboost_python.so: undefined reference to `PyString_Size' - caffe install ERROR libboost_python.so: undefined reference to `PyString_Size' Skip to content All gists Back to GitHub

[Tutor] Making python extension in Windows, | 1 Answers. up vote 3 down vote ---Accepted---Accepted---Accepted---. The order of libraries on the link line matters, and your order is wrong. | this answer answered May 5 '13 at 16:34 Employed Russian 95.2k 15 130 189

4612 (build Twisted on 64-bit Windows with mingw), 1) gendef.exe python27.dll 2) dlltool.exe --dllname python27.dll --def python27.def --output-lib libpython27.a 3) Copy libpython27.a to C:\Python27\libs Strangely, gendef has already used Py_InitModule4_64 but I need to rename it back to Py_InitModule4 to get the Python binding build successfully. But the resultant Python bindings do not work.

Compiling Python , Hi Broes, Clingo can be compiled under Windows. I tested with Cygwin and Visual Studio. The latter produces the most efficient binaries; and the community edition can be downloaded for free.

Comments
  • python_d setup.py build --debug -c mingw32 is the command line
  • It's not recommended to use MinGW (or any of its forks) with the official WIndows Python builds (or any other MSVC build), for the reasons explained at bugs.python.org/issue4709#msg243605.
  • This was my fix too. Thanks!
  • @tiho Hi, I have a similar problem at stackoverflow.com/questions/18956136/… Can you help me with this? In my case, I am not using Boost to build the binaries with command line. I am simply trying to build a Hello World example. It should be very easy, but now it is driven me crazy... Thanks.
  • No need to mess with your installed distutils module. Just add define_macros=[('MS_WIN64',None)] as an argument to the setup call in setup.py.