使用MinGW编译Cython – 未定义的引用PyExc

我正在尝试从“Cython – Python程序员指南”一书中编译一个简单的代码片段,当我编译时,我收到以下错误:

H:\Cython>python setup.py build_ext -i --compiler=mingw32 running build_ext building 'fib' extension C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Anaconda3\include -IC:\Anaconda3\include -c fib.c -o build\temp.win32-3.4\Release\fib.o writing build\temp.win32-3.4\Release\fib.def C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-3.4\Release\fib.o build\temp.win32-3.4\Release\fib.def -LC:\Anaconda3\libs -LC:\Ana conda3\PCbuild -lpython34 -lmsvcr100 -o H:\Cython\fib.pyd build\temp.win32-3.4\Release\fib.o:fib.c:(.text+0xb6): undefined reference to `_imp__PyExc_TypeError' build\temp.win32-3.4\Release\fib.o:fib.c:(.text+0xf3): undefined reference to `_imp__PyExc_TypeError' build\temp.win32-3.4\Release\fib.o:fib.c:(.text+0x3cc): undefined reference to `_imp___PyThreadState_Current' build\temp.win32-3.4\Release\fib.o:fib.c:(.text+0x857): undefined reference to `_imp__PyExc_NameError' build\temp.win32-3.4\Release\fib.o:fib.c:(.text+0xa55): undefined reference to `_imp__PyExc_ImportError' c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: build\temp.win32-3.4\Release\fib.o: bad reloc address 0x0 in s ection `.data' collect2.exe: error: ld returned 1 exit status error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1 H:\Cython> 

setup.py:

 from distutils.core import setup from Cython.Build import cythonize setup(ext_modules=cythonize('fib.pyx')) 

fib.pyx:

 def fib(int n): cdef int i cdef double a=0.0, b=1.0 for i in range(n): a, b = a + b, a return a 

当我谷歌这个问题时,其他有错误的人混合了32到64位的东西,我不是那样做的。

我今天坐下来再次看错了,发现了问题。 问题是我使用Anaconda而不是自己编译所有东西 – 这意味着一些Cython组件是用MSVC编译的。 如上所示,您可以看到我正在尝试使用MinGW来编译Cython测试脚本。 为什么混合这样的编译器不起作用超出了我的知识范围,但事实并非如此。 使用MSVC编译我的Cython测试脚本。
(分别使用Visual Studio C ++ 2008/2010 for python 2.x / 3.x)

至于我试图使用MinGW(违反标准推荐)的原因是我的msiserver服务有所破坏(我在旧笔记本电脑上,所以我不记得原因),并希望找到一个快速的方法out,而不是修复msiserver服务。

msiserver服务的修复与这个问题非常无关,但它很难找到,所以我想我会在这里链接并镜像它:

http://www.vistax64.com/vista-installation-setup/96680-repair-windows-installer-service-vista-all-versions.html

对于所有那些不幸的搜索和谷歌搜索如何修复Windows安装程序服务的灵魂,我有一些信息给你。 几天前,我试图卸载我的一个应用程序并因错误“无法访问Windows Installer服务”而停滞不前。 在尝试解决此问题的许多试验和错误之后,我偶然发现了一个针对此问题的新修复程序,该修复程序在Windows Installer服务无法手动启动且无需安装或卸载任务的所有情况下都能正常运行。

这是简单的步骤:

 1. Go to a Windows Vista (Any Version) computer that has the Windows Installer service running correctly and run regedit(Start-Run-Regedit) 2. Go to the location HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\msiserver 3. Right click on this key and select "Export" and save the key to a Flash Drive or other. 4. Run sfc /scannow on the damaged Vista computer - you won't need the install disk as it goes to backup files on your HD. Do not reboot when complete 5. Double click saved .reg file from working machine and import registry settings into damaged Vista computer. 6. Now reboot and try to install/uninstall 

如果你们中的许多人都成功使用这种方法,请在WWW上发布此修复程序,因为我遇到了超过1000个链接,用户遇到了同样的问题并且无法解决问题。 对微软感到羞耻,非常草率。 如果微软发布Windows安装4.0作为Vista版本的独立安装,那将是非常好的,所以我可以修复它,大多数用户都在进行全新安装来解决这个问题。 让你的行为一起微软!!!!

那只猫

谢谢,猫。