Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

installation - Cython error: C:Python27libs/libpython27.a: error adding symbols

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:MinGWingcc.exe -mdll -O -Wall -IC:Python27include -IC:Python27PC -c he
llo.c -o buildemp.win32-2.7Releasehello.o
writing buildemp.win32-2.7Releasehello.def
C:MinGWingcc.exe -shared -s buildemp.win32-2.7Releasehello.o buildemp.
win32-2.7Releasehello.def -LC:Python27libs -LC:Python27PCbuild -lpython27
-lmsvcr90 -o C:UsersBerndDocuments99_ProjekteONGOING201412_Laufauswertung
ReproTestshello.pyd
C:Python27libs/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:Python27libs (for example bak subdirectory), and copy python27.dll from c:windowssystem32 to c:python27libs

Now the result is:

C:[...]>python setup.py build_ext --inplace
running build_ext
building 'hello' extension
C:MinGWingcc.exe -mdll -O -Wall -IC:Python27include -IC:Python27PC -c he
llo.c -o buildemp.win32-2.7Releasehello.o
writing buildemp.win32-2.7Releasehello.def
C:MinGWingcc.exe -shared -s buildemp.win32-2.7Releasehello.o buildemp.
win32-2.7Releasehello.def -LC:Python27libs -LC:Python27PCbuild -lpython27
-lmsvcr90 -o C:UsersBerndDocuments99_ProjekteONGOING201412_Laufauswertung
ReproTestshello.pyd
buildemp.win32-2.7Releasehello.o:hello.c:(.text+0x2d9): undefined reference
to `_imp___PyThreadState_Current'
buildemp.win32-2.7Releasehello.o:hello.c:(.text+0x3b3): undefined reference
to `_imp__PyExc_RuntimeError'
buildemp.win32-2.7Releasehello.o:hello.c:(.text+0x444): undefined reference
to `_imp___Py_NoneStruct'
buildemp.win32-2.7Releasehello.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 buildemp.win32-2.7Release 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...