Cython错误:C:\ Python27 \ libs / libpython27.a:添加符号时出错

时间:2016-01-20 22:34:44

标签: installation cython

我正在使用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\99_Projekte\ONGOING\201412_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子目录),并从python27.dll

复制c:\windows\system32 to c:\python27\libs

现在的结果是:

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\99_Projekte\ONGOING\201412_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\Releasehello.def的文件夹hello.o

编辑2: 也许解决方案在这里:compiling Cython with MinGW - undefined reference PyExc

我将尝试安装Visual Studio,然后再试一次。关于如何使它在MinGW上运行的建议仍然很好。

1 个答案:

答案 0 :(得分:2)

如果安装了工具 gendef dlltool ,则可以在临时目录中使用以下内容(假设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文件。