本文介绍了Cython错误:C:\Python27\libs / libpython27.a:添加符号时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Cython做第一次测试。基本上是



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

  C:[...]> python setup.py build_ext --inplace 
编译hello.pyx,因为它已更改。
[1/1] Cythonizing hello.pyx
运行build_ext
构建'hello'扩展名
C:\MinGW\bin\gcc.exe -mdll -O- Wall -IC:\Python27\include -IC:\Python27\PC -c
llo.c -o build\temp.win32-2.7\Release\hello.o
编写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\发布\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:添加符号时出错:文件无法识别格式

collect2.exe:错误:ld返回1退出状态
错误:命令'C:\\MinGW\\bin\\gcc.exe'失败,退出状态为1

文件 hello.c 生成。



有什么想法吗?



编辑1:



按照JJ的提示哈卡,我做了以下工作:将 libpython27.a C:\Python27\libs 移开(例如bak子目录),然后将 python27.dll c:\windows\system32复制到c:\python27\libs



现在的结果是:

  C:[ ...]> python setup.py build_ext --inplace 
运行build_ext
构建 hello扩展名
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
写build\temp.win32-2.7\发行\hello.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\释放\hello.o build\temp。
win32-2.7\发布\hello.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27
-lmsvcr90 -o C:\Users\ Bernd\文档\99_Projekte\ONGOING\201412_Laufauswertung\
Repro\Tests\hello.pyd
build\temp.win32-2.7\Release\hello.o:hello .c :(。text + 0x2d9):未定义引用
到'_imp___PyThreadState_Current'
build\temp.win32-2.7\Release\hello.o:hello.c :(。text + 0x3b3 ):未定义引用
到'_imp__PyExc_RuntimeError'
build\temp.win32-2.7\Release\hello.o:hello.c :(。text + 0x444):未定义引用
到'_imp___Py_NoneStruct'
build\temp.win32-2.7\Release\hello.o:hello.c :(。text + 0x8e1):未定义引用
到'_imp__PyExc_ImportError'
collect2.exe:错误:ld返回1退出状态
错误:命令'C:\\MinGW\\bin\\gcc.exe'失败,退出状态为1

文件夹 build\temp.win32-2.7\发布生成文件 hello.def hello.o



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



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

解决方案

如果使用工具 gendef 和 dlltool ,在临时目录(假设为msys或cygwin环境)中应该可以进行以下操作:

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

必要时替换 C:/ Python27



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

I'm doing my first test with Cython. Basically the hello.pyx example from http://docs.cython.org/src/quickstart/build.html

When I want to compile I get the following error:

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

The file hello.c is generated.

Any idea?

Edit 1:

Following the hint from J.J. Hakala, i did the following: move libpython27.a away from C:\Python27\libs (for example bak subdirectory), and copy python27.dll from c:\windows\system32 to c:\python27\libs

Now the result is:

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

A folder build\temp.win32-2.7\Release with the files hello.def and hello.o is generated.

Edit 2:Maybe the solution is here: compiling Cython with MinGW - undefined reference PyExc

I'll try to install Visual Studio and then try again. Recommendation on how to make it run on MinGW are still wellcome.

解决方案

If tools gendef and dlltool are installed, the following should be possible in a temporary directory (assuming msys or cygwin environment):

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

Substitute C:/Python27 if necessary.

gcc will now use the generated file instead of some existing .a or .lib file.

这篇关于Cython错误:C:\Python27\libs / libpython27.a:添加符号时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:09