使用 MinGW 编译 Cython - 未定义参考 PyExc
compiling Cython with MinGW - undefined reference PyExc
我正在尝试编译 "Cython - A guide for Python programmers" 书中的一个简单代码片段,当我编译时,出现以下错误:
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
当我 google 这个问题时,其他遇到错误的人混合了 32 位和 64 位的东西,我没有这样做。
今天我坐下来再次查看错误,发现了问题所在。
问题是我使用的是 Anaconda 而不是自己从头开始编译所有内容——这意味着一些 Cython 组件是用 MSVC 编译的。如上你可以看到我正在尝试使用 MinGW 来编译 Cython 测试脚本。为什么混合这样的编译器不起作用超出了我的知识范围,但事实并非如此。使用 MSVC 编译我的 Cython 测试脚本。
(分别对 python 2.x/3.x 使用 Visual Studio C++ 2008/2010)
至于我尝试使用 MinGW(违背标准建议)的原因是我的 msiserver 服务不知何故坏了(我在一台旧笔记本电脑上,所以我不记得原因),并且希望找到一个快速的出路,而不是修复 msiserver 服务。
msiserver 服务的修复与这个问题完全无关,但它很难找到,所以我想我 link 并在此处进行镜像:
For all those unfortunate souls searching and Googling for how to
repair the Windows Installer Service, I have some info for you. A
couple days ago I tried to uninstall one of my apps and stalled on an
error "Windows Installer Service cannot be accessed". After many
trials and errors trying to fix this issue, I stumbled upon a new fix
for this issue that has worked in all these situations where the
Windows Installer Service will not manually start and in essense, not
allow install or uninstall tasks to complete.
Here's the easy steps:
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
If many of you have success with this method, please post this fix
around the WWW as I went through over 1000 links with users having the
same problem and not being able to solve it. Shame on Microsoft, very
sloppy. It would have been so nice if Microsoft released Windows
Installer 4.0 as a standalone installation with Vista's release so I
could have repaired it, most users have been doing fresh installs to
fix this. Get your act together Microsoft!!!!
The CAT
谢谢你,猫
我正在尝试编译 "Cython - A guide for Python programmers" 书中的一个简单代码片段,当我编译时,出现以下错误:
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
当我 google 这个问题时,其他遇到错误的人混合了 32 位和 64 位的东西,我没有这样做。
今天我坐下来再次查看错误,发现了问题所在。
问题是我使用的是 Anaconda 而不是自己从头开始编译所有内容——这意味着一些 Cython 组件是用 MSVC 编译的。如上你可以看到我正在尝试使用 MinGW 来编译 Cython 测试脚本。为什么混合这样的编译器不起作用超出了我的知识范围,但事实并非如此。使用 MSVC 编译我的 Cython 测试脚本。
(分别对 python 2.x/3.x 使用 Visual Studio C++ 2008/2010)
至于我尝试使用 MinGW(违背标准建议)的原因是我的 msiserver 服务不知何故坏了(我在一台旧笔记本电脑上,所以我不记得原因),并且希望找到一个快速的出路,而不是修复 msiserver 服务。
msiserver 服务的修复与这个问题完全无关,但它很难找到,所以我想我 link 并在此处进行镜像:
For all those unfortunate souls searching and Googling for how to repair the Windows Installer Service, I have some info for you. A couple days ago I tried to uninstall one of my apps and stalled on an error "Windows Installer Service cannot be accessed". After many trials and errors trying to fix this issue, I stumbled upon a new fix for this issue that has worked in all these situations where the Windows Installer Service will not manually start and in essense, not allow install or uninstall tasks to complete.
Here's the easy steps:
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
If many of you have success with this method, please post this fix around the WWW as I went through over 1000 links with users having the same problem and not being able to solve it. Shame on Microsoft, very sloppy. It would have been so nice if Microsoft released Windows Installer 4.0 as a standalone installation with Vista's release so I could have repaired it, most users have been doing fresh installs to fix this. Get your act together Microsoft!!!!
The CAT
谢谢你,猫