Windows 7 cython:mingw内存视图生成错误

Windows 7 cython:mingw内存视图生成错误,windows-7,numpy,mingw,cython,memoryview,Windows 7,Numpy,Mingw,Cython,Memoryview,我一直在用cython编写一些python扩展模块。我编写的扩展构建得很好,工作也很好。然后,我想在访问numpy数组时使用类型化MemoryView,因为它们似乎有几个优点 但是,只要我在cython代码中使用memoryview,我就会在构建扩展时出错。例如,如果我添加此测试行: cdef double[:,::1]X=np.零((100100)) 到现有的工作cython扩展。我将得到以下错误: C:\MinGW\bin\gcc.exe -shared -s build\temp.win3

我一直在用cython编写一些python扩展模块。我编写的扩展构建得很好,工作也很好。然后,我想在访问numpy数组时使用类型化MemoryView,因为它们似乎有几个优点

但是,只要我在cython代码中使用memoryview,我就会在构建扩展时出错。例如,如果我添加此测试行:

cdef double[:,::1]X=np.零((100100))

到现有的工作cython扩展。我将得到以下错误:

C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\image_box.o build\temp.win32-2.7\Release\image_box.def -Lc:\python27\libs -Lc:\python27\PCbuild -lp
ython27 -lmsvcr90 -o x:\ARframework\python\image_ops\image_box.pyd
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0xe23): undefined reference to `___sync_fetch_and_add_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x3318): undefined reference to `___sync_fetch_and_add_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x4c81): undefined reference to `___sync_fetch_and_sub_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x4d37): undefined reference to `___sync_fetch_and_sub_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x10767): undefined reference to `___sync_fetch_and_sub_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x10793): undefined reference to `___sync_fetch_and_sub_4'
collect2.exe: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
我尝试将-march=i486添加到gcc行中,正如本文所建议的: 但这并没有解决问题。为此,我还尝试了-march=i586和-march=pentium,但没有成功

知道这是怎么回事吗

我的平台是Windows7,mingw版本是4.70,Cython版本是0.17.1

谢谢,我找到了解决办法

实际上,gcc标志-march=i486确实解决了这个问题!然而,当我在控制台中测试它时,我只是将它应用于链接步骤的gcc行(这就是我得到错误的地方),由于它没有解决问题,我认为它根本不起作用。 事实上,我需要在编译和链接步骤中使用-march=i486,这样就没有错误了

至于如何在构建扩展时包含这些标志,我尝试添加

import os
os.environ['LDFLAGS'] = '-march=i486'
os.environ['CFLAGS'] = '-march=i486'
安装到setup.py,但它似乎不起作用


因此,我修改了c:\python27\Lib\distutils\cygwinccompiler.py,以便在编译和链接步骤中包含这些标志。不确定这是否是设置这些标志的非常优雅的方式。欢迎任何选择

如果你使用新的或改变的方法,你必须调整你的方法。def文件。这一点经常被忽视。只想在没有
build\temp.win32-2.7\Release\image\u box.o build\temp.win32-2.7\Release\image\u box.def
的情况下进行测试。我不太明白你的意思。我已删除build\temp.win32-2.7\Release\image\u box.o build\temp.win32-2.7\Release\image\u box.def并尝试再次构建扩展,问题仍然存在,请使用
C:\MinGW\bin\gcc.exe-shared-s build\temp.win32-2.7\Release\image\u box.o-Lc:\python27\libs-Lc:\python27\PCbuild-lp
进行构建。哦,我们必须同时发布。如果将标志-march=i486应用于编译和链接步骤,则似乎可以解决此问题。出于好奇,我尝试了你的行(没有.def文件),但仍然有错误。无论如何谢谢你