Cython error: C:\Python27\libs/libpython27.a: error adding symbols

Cython error: C:\Python27\libs/libpython27.a: error adding symbols

我正在用 Cython 进行第一次测试。基本上 http://docs.cython.org/src/quickstart/build.html

中的 hello.pyx 示例

当我想编译时出现以下错误:

C:[...]>python setup.py build_ext --inplace
Compiling hello.pyx because it changed.
[1/1] Cythonizing hello.pyx
running build_ext
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c he
llo.c -o build\temp.win32-2.7\Release\hello.o
writing build\temp.win32-2.7\Release\hello.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\hello.o build\temp.
win32-2.7\Release\hello.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27
-lmsvcr90 -o C:\Users\Bernd\Documents_Projekte\ONGOING1412_Laufauswertung\
Repro\Tests\hello.pyd
C:\Python27\libs/libpython27.a: error adding symbols: File format not recognized

collect2.exe: error: ld returned 1 exit status
error: command 'C:\MinGW\bin\gcc.exe' failed with exit status 1

生成文件hello.c

有什么想法吗?

编辑 1:

遵循 J.J 的提示。 Hakala,我做了以下操作:将 libpython27.a 移出 C:\Python27\libs(例如 bak 子目录),并从 c:\windows\system32 to c:\python27\libs

复制 python27.dll

现在的结果是:

C:[...]>python setup.py build_ext --inplace
running build_ext
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c he
llo.c -o build\temp.win32-2.7\Release\hello.o
writing build\temp.win32-2.7\Release\hello.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\hello.o build\temp.
win32-2.7\Release\hello.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27
-lmsvcr90 -o C:\Users\Bernd\Documents_Projekte\ONGOING1412_Laufauswertung\
Repro\Tests\hello.pyd
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x2d9): undefined reference
to `_imp___PyThreadState_Current'
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x3b3): undefined reference
to `_imp__PyExc_RuntimeError'
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x444): undefined reference
to `_imp___Py_NoneStruct'
build\temp.win32-2.7\Release\hello.o:hello.c:(.text+0x8e1): undefined reference
to `_imp__PyExc_ImportError'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\MinGW\bin\gcc.exe' failed with exit status 1

生成一个文件夹 build\temp.win32-2.7\Release,其中包含文件 hello.defhello.o

编辑 2: 也许解决方案在这里:

我会尝试安装 Visual Studio,然后重试。关于如何在 MinGW 上制作它的建议 运行 仍然欢迎。

如果安装了工具 gendefdlltool,则在临时目录中应该可以执行以下操作(假设是 msys 或 cygwin 环境):

gendef c:/Windows/System32/python27.dll
dlltool -U -d python27.def -l libpython27.dll.a
cp libpython27.dll.a c:/Python27/libs

如有必要,替换为 C:/Python27

gcc 现在将使用生成的文件而不是一些现有的 .a.lib 文件。