【问题标题】:Cython hello world example is not working windowsCython hello world 示例无法正常工作
【发布时间】:2013-09-16 15:28:44
【问题描述】:

大家好,提前感谢。

我正在测试 Cython,我已经开始了最简单的情况,但是在编译时遇到了错误。使用:Python 2.7,最新的 cython 和 minGW。我已经编辑了 cygwinccompiler.py 并删除了 -mno-cygwin 行。

C:\Playground\demo_heeds\cython_test>python setup.py build_ext --inplace
running build_ext
skipping 'hello.c' Cython extension (up-to-date)
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c he
llo.c -o build\temp.win-amd64-2.7\Release\hello.o
writing build\temp.win-amd64-2.7\Release\hello.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-2.7\Release\hello.o build\t
emp.win-amd64-2.7\Release\hello.def -LC:\Python27\libs -LC:\Python27\PCbuild\amd
64 -lpython27 -lmsvcr90 -o C:\Playground\demo_heeds\cython_test\hello.pyd
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x8b): undefined referen
ce to `_imp__PyOS_snprintf'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x93): undefined referen
ce to `_imp__Py_GetVersion'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0xfb): undefined referen
ce to `_imp__PyOS_snprintf'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x114): undefined refere
nce to `_imp__PyErr_WarnEx'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x12e): undefined refere
nce to `_imp__PyTuple_New'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x150): undefined refere
nce to `_imp__PyString_FromStringAndSize'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x18a): undefined refere
nce to `_imp__Py_InitModule4'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x1a3): undefined refere
nce to `_imp__PyModule_GetDict'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x1c0): undefined refere
nce to `_imp__PyImport_AddModule'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x1e7): undefined refere
nce to `_imp__PyObject_SetAttrString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x208): undefined refere
nce to `_imp__PyString_FromStringAndSize'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x20e): undefined refere
nce to `_imp__PyString_InternFromString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x232): undefined refere
nce to `_imp__PyUnicodeUCS2_DecodeUTF8'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x294): undefined refere
nce to `_imp__PyObject_SetAttrString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x2af): undefined refere
nce to `_imp__PySys_GetObject'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x2c6): undefined refere
nce to `_imp__PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x2d1): undefined refere
nce to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x2e7): undefined refere
nce to `_imp__PyFile_WriteString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x300): undefined refere
nce to `_imp__PyFile_WriteObject'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x315): undefined refere
nce to `_imp__PyFile_WriteString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x36e): undefined refere
nce to `_imp__PyDict_SetItem'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x3ef): undefined refere
nce to `_imp__PyString_FromString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x41a): undefined refere
nce to `_imp__PyString_FromFormat'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x480): undefined refere
nce to `_imp__PyCode_New'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x4db): undefined refere
nce to `_imp__PyMem_Malloc'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x56f): undefined refere
nce to `_imp__PyMem_Realloc'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x5d9): undefined refere
nce to `_imp__PyModule_GetDict'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x5f7): undefined refere
nce to `_imp___PyThreadState_Current'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x602): undefined refere
nce to `_imp__PyFrame_New'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x618): undefined refere
nce to `_imp__PyTraceBack_Here'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x676): undefined refere
nce to `_imp__PyErr_Occurred'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x68b): undefined refere
nce to `_imp__PyExc_ImportError'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x696): undefined refere
nce to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x6e9): undefined refere
nce to `_imp__PyFile_SoftSpace'
build\temp.win-amd64-2.7\Release\hello.o:hello.c:(.text+0x707): undefined refere
nce to `_imp__PyDict_New'`enter code here`
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: build\temp
.win-amd64-2.7\Release\hello.o: bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

【问题讨论】:

  • 你有没有 64 位 python 但有 32 位 gcc,反之亦然?
  • 我有 64 位 Python 和 32 位 gcc...这可能是您所说的问题-谢谢
  • 现在一切正常:)
  • 供将来参考,此问题已在 wiki.cython.org/InstallingOnWindows#Troubleshooting 中解决。如果您想要 64 位窗口所需的文件,您可以在 lfd.uci.edu/~gohlke/pythonlibs/#libpython 获取它们,而不是像 Cython 网站上讨论的那样生成它们。可以使用 32 位安装的 MinGW 构建对 64 位 Python 的扩展,但设置起来很痛苦。据我了解,这就是 EPD 和 Anaconda 目前的工作方式。您可能还需要从 distutils 中的 cygwincompiler.py 文件中删除“-mno-cygwin”标志以使其正常工作。
  • 我遇到了同样的错误,但使用的是 32 位版本的 Python 2.7.10 和 mingw32。有什么想法吗?

标签: python windows mingw cython


【解决方案1】:

好的。为避免在 cmets 中丢失答案:

编译器是 32 位 gcc 编译器,而 Python 是 64 位编译器。这行不通。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 2016-05-15
    相关资源
    最近更新 更多