Compiling with cython and mingw produces gcc: error: unrecognized command line option '-mno-cygwin' Compiling with cython and mingw produces gcc: error: unrecognized command line option '-mno-cygwin' python python

Compiling with cython and mingw produces gcc: error: unrecognized command line option '-mno-cygwin'


It sounds like GCC 4.7.0 has finally removed the deprecated -mno-cygwin option, but distutils has not yet caught up with it. Either install a slightly older version of MinGW, or edit distutils\cygwinccompiler.py in your Python directory to remove all instances of -mno-cygwin.


During the process of solving these and the following problems I found, I wrote a recipe in this thread. I reproduce it here in case it could be of utility for others:


Step by step recipe to compile 64-bit cython extensions with python2.6.6 with mingw compiler in win 7 64-bit

Install mingw compiler
1) Install tdm64-gcc-4.5.2.exe for 64-bit compilation

Apply patch to python.h
2) Modify python.h in C:\python26\include as indicated inhttp://bugs.python.org/file12411/mingw-w64.patch

Modify distutils
Edit 2013: Note than in python 2.7.6 and 3.3.3 -mno-cygwin has been finally removed so step 3 can be skipped.

3) Eliminate all the parameters -mno-cygwin fom the call to gcc in theMingw32CCompiler class in Python26\Lib\distutils\cygwinccompiler.py
4) In the same module, modify get_msvcr() to return an empty listinstead of ['msvcr90'] when msc_ver == '1500' .

Produce the libpython26.a file (not included in 64 bit python)
Edit 2013: the following steps 5-10 can be skipped by downloading and installing libpython26.a from gohlke.

5) Obtain gendef.exe from mingw-w64-bin_x86_64-mingw_20101003_sezero.zip (gendef.exe is not available in the tmd64 distribution. Anothersolution is to compile gendef from source...)
6) Copy python26.dll (located at C\windows\system32) to the userdirectory (C:\Users\myname)
7) Produce the python26.def file with:

gendef.exe C:\Users\myname\python26.dll

8) Move the python.def file produced (located in the folder from wheregendef was executed) to the user directory
9) Produce the libpython.a with:

dlltool -v --dllname python26.dll --def C:\Users\myname \python26.def --output-lib C:\Users\myname\libpython26.a

10) Move the created libpython26.a to C:\Python26\libs

Produce your .pyd extension
11) Create a test hello.pyx file and a setup.py file as indicated incython tutorial (http://docs.cython.org/src/quickstart/build.html)
12) Compile with

python setup.py build_ext --inplace

Done!


This bug has now been fixed in Python 2.7.6 release candidate 1.

The patching commit is here.

The resolved issue tracker thread is here.