用cython和mingw编译生成gcc:错误:未识别的命令行选项“-mno-cygwin”

时间:2021-07-23 23:19:32

I'm trying to compile a python extension with cython in win 7 64-bit using mingw (64-bit).
I'm working with Python 2.6 (Active Python 2.6.6) and with the adequate distutils.cfg file (setting mingw as the compiler)

我正在尝试通过使用mingw(64位)来编译一个带有cython的python扩展。我正在使用Python 2.6 (Active Python 2.6.6)和适当的distutils。cfg文件(将mingw设置为编译器)

When executing

在执行

> C:\Python26\programas\Cython>python setup.py build_ext --inplace

I get an error saying that gcc has not an -mno-cygwin option:

我有一个错误,说gcc没有-mno-cygwin选项:

> C:\Python26\programas\Cython>python setup.py build_ext --inplace
running build_ext
skipping 'hello2.c' Cython extension (up-to-date)
building 'hello2' extension
C:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Python26\PC -c hello2.c -o build\temp.win-amd64-2.6\Release\hello2.o
gcc: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1

gcc is:

gcc是:

C:\>gcc --version
gcc (GCC) 4.7.0 20110430 (experimental)
Copyright (C) 2011 Free Software Foundation, Inc.

How could I fix it?

我怎么能修好它?

4 个解决方案

#1


178  

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.

这听起来好像GCC 4.7.0终于去掉了不推荐的-mno-cygwin选项,但是distutils还没有赶上它。或者安装一个稍微老一点的MinGW,或者编辑distutils\cygwinccompiler。py在Python目录中删除-mno-cygwin的所有实例。

#2


11  

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 python 2.6.6 with mingw compiler in win 7 64-bit

一步一步,通过python 2.6.6和mingw编译器在win 7 64位中编译64位的cython扩展。

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

安装mingw编译器1)安装tdm64-gcc-4.5.2。exe编译64位

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

对python应用补丁。h 2)修改python。在C:\python26\包括如http://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.

修改distutils编辑2013:请注意,python 2.7.6和3.3.3 -mno-cygwin最终被删除,所以步骤3可以跳过。

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

3)消除所有参数-mno-cygwin fom在Python26\Lib\distutils\ cygwinc编译器的Mingw32CCompiler类中调用gcc。在同一个模块中,修改get_msvcr()以返回空列表,而不是msc_ver == '1500'时返回的['msvcr90']。

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.

产生libpython26。一个文件(不包含在64位python中)编辑2013:通过下载和安装libpython26可以跳过以下步骤5-10。从gohlke。

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

5)获得gendef。从mingw-w64-bin_x86_64——mingw_20101003_sezero exe。邮政编码(gendef。exe在tmd64分布中不可用。另一种解决方案是从源代码编译gendef .)复制python26。dll(位于C\windows\system32)到用户目录(C:\Users\myname) 7)生成python26.def文件:

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

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

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

将生成的python.def文件(位于gendef执行的文件夹中)转移到用户目录9)生成libpython。一个:

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

dlltool - v - dllname python26。usersmyname \python26.def - outputlib c:usersmyname\ libpython26.a。

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

10)移动创建的libpython26。a到C:\ Python26 \ lib中

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

生成您的.pyd扩展名创建一个测试hello。pyx文件和设置。如cython教程中所示的py文件(http://docs.cython.org/src/quickstart/build.html)编译。

python setup.py build_ext --inplace

python的设置。py build_ext——原地

Done!

完成了!

#3


9  

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

这个bug现在已经被固定在Python 2.7.6版本的候选版本1中。

The patching commit is here.

补丁包在这里。

The resolved issue tracker thread is here.

已解析的问题跟踪线程在这里。

#4


-2  

Try this . It really works for the error
https://github.com/develersrl/gccwinbinaries

试试这个。它确实适用于错误https://github.com/develersrl/gccwinbinaries。

#1


178  

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.

这听起来好像GCC 4.7.0终于去掉了不推荐的-mno-cygwin选项,但是distutils还没有赶上它。或者安装一个稍微老一点的MinGW,或者编辑distutils\cygwinccompiler。py在Python目录中删除-mno-cygwin的所有实例。

#2


11  

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 python 2.6.6 with mingw compiler in win 7 64-bit

一步一步,通过python 2.6.6和mingw编译器在win 7 64位中编译64位的cython扩展。

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

安装mingw编译器1)安装tdm64-gcc-4.5.2。exe编译64位

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

对python应用补丁。h 2)修改python。在C:\python26\包括如http://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.

修改distutils编辑2013:请注意,python 2.7.6和3.3.3 -mno-cygwin最终被删除,所以步骤3可以跳过。

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

3)消除所有参数-mno-cygwin fom在Python26\Lib\distutils\ cygwinc编译器的Mingw32CCompiler类中调用gcc。在同一个模块中,修改get_msvcr()以返回空列表,而不是msc_ver == '1500'时返回的['msvcr90']。

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.

产生libpython26。一个文件(不包含在64位python中)编辑2013:通过下载和安装libpython26可以跳过以下步骤5-10。从gohlke。

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

5)获得gendef。从mingw-w64-bin_x86_64——mingw_20101003_sezero exe。邮政编码(gendef。exe在tmd64分布中不可用。另一种解决方案是从源代码编译gendef .)复制python26。dll(位于C\windows\system32)到用户目录(C:\Users\myname) 7)生成python26.def文件:

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

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

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

将生成的python.def文件(位于gendef执行的文件夹中)转移到用户目录9)生成libpython。一个:

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

dlltool - v - dllname python26。usersmyname \python26.def - outputlib c:usersmyname\ libpython26.a。

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

10)移动创建的libpython26。a到C:\ Python26 \ lib中

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

生成您的.pyd扩展名创建一个测试hello。pyx文件和设置。如cython教程中所示的py文件(http://docs.cython.org/src/quickstart/build.html)编译。

python setup.py build_ext --inplace

python的设置。py build_ext——原地

Done!

完成了!

#3


9  

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

这个bug现在已经被固定在Python 2.7.6版本的候选版本1中。

The patching commit is here.

补丁包在这里。

The resolved issue tracker thread is here.

已解析的问题跟踪线程在这里。

#4


-2  

Try this . It really works for the error
https://github.com/develersrl/gccwinbinaries

试试这个。它确实适用于错误https://github.com/develersrl/gccwinbinaries。