本文介绍了编译pyx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习cython,这是我第一次尝试编译.pyx文件。
我尝试在我的cmd中运行:

这给了我的fib.c文件。

然后我运行:

$ b

这给了我我的fib.o文件,但是当我试图

它给了我这个例外:

  fib.o: fib.c :(。text + 0x72):未定义的对`_imp__PyObject_GetAttr'的引用
fib.o:fib.c :( .text + 0xdb):对'_imp__PyErr_Occurred'的未定义引用
fib.o: (.text + 0x26c):对_imp__PyString_FromString'
的未定义引用fib.o:fib.c :(。text + 0x2ae):对'_imp__PyNumber_Add'的未定义引用
fib.o: fib.c :( .text + 0x31c):对_imp__PyMethod_Type的未定义引用
fib.o:fib.c :( .text + 0x418):对`_imp__PyTuple_New'的未定义引用
fib.o: fib.c :(文字+ 0x53b):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :(。text + 0x543):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :( .text + 0x54d):未定义的对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :( .text + 0x79d):对_imp__PyNumber_Add的未定义引用
fib.o:fib.c :( .text + 0x874):未定义的引用'_imp__PyList_Type'
fib.o:fib.c :(。text + 0x88b):未定义的引用'_imp__PyTuple_Type'
fib.o:fib.c :(。text + 0x8c4):对`_imp__PyObject_GetIter'的未定义引用
fib.o:fib.c :(。text + 0x972):对`_imp__PyList_Type'的未定义引用
fib.o:fib.c :( .text + 0xa0b):未定义的对`_imp__PyErr_Occurred'的引用
fib.o:fib.c :( .text + 0xa1b):未定义的引用'_imp__PyExc_StopIteration'
fib.o:fib.c :( .text + 0xa2f):未定义对`_imp__PyExc_StopIteration'的引用
fib.o:fib.c :( .text + 0xa40):未定义对`_imp__PyErr_GivenExceptionMatches'的引用
fib.o:fib.c :( .text + 0xa53):未定义的参考` _imp__PyErr_Clear'
fib.o:fib.c :(。text + 0xac3):未定义对`_imp__PyTuple_New'的引用
fib.o:fib.c :( .text + 0xcec) _imp__PyString_FromString'
fib.o:fib.c :(。text + 0xd2e):未定义对`_imp__PyNumber_Add'的引用
fib.o:fib.c :( .text + 0xd96):undefined指向` _imp__PyTuple_New'
fib.o:fib.c :( .text + 0xe9e):对`_imp__PyString_FromString'的未定义引用
fib.o:fib.c :( .text + 0xee0):未定义引用` _imp__PyNumber_Add'
fib.o:fib.c :(。text + 0xf48):未定义对`_imp__PyTuple_New'的引用
fib.o:fib.c :( .text + 0x107c):未定义引用` _imp__PyMethod_Type'
fib.o:fib.c :(。text + 0x11d9):未定义对`_imp__PyList_Type'的引用
fib.o:fib.c :( .text + 0x11f0):未定义引用` _imp__PyTuple_Type'
fib.o:fib.c :(。text + 0x1229):未定义对`_imp__PyObject_GetIter'的引用
fib.o:fib.c :( .text + 0x12d7) _imp__PyList_Type'
fib.o:fib.c :(。text + 0x1370):'_imp__PyErr_Occurred'的未定义引用
fib.o:fib.c :( .text + 0x1380):对`_imp__PyExc_StopIteration'的未定义引用
fib.o:fib.c :( .text + 0x1394):未定义的对`_imp__PyExc_StopIteration'的引用
fib.o:fib.c :(。text + 0x13a5):对`_imp__PyErr_GivenExceptionMatches'的未定义引用
fib.o:fib.c :( .text + $ _ $ b $ fib.o:fib.c :(。text + 0x1472):未定义对`_imp__PyMethod_Type'的引用
fib.o:fib.c :(。text + 0x13b8):对'_imp__PyErr_Clear' $ _ $ b $ fib.o:fib.c :(。text + 0x183e):未定义对`_imp__PyMethod_Type'的引用
fib.o:fib.c :(。text + 0x153f):`_imp__PyTuple_New' $ _ $ b $ fib.o:fib.c :(。text + 0x19c8):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :(。text + 0x19c0):对`_imp___Py_NoneStruct' 0x19d2):对_imp___Py_NoneStruct的未定义引用
fib.o:fib.c :( .text + 0x1c16):对_imp__PyObject_GC_Track'
的未定义引用fib.o:fib.c :( .text + 0x1c67):你对_imp__PyObject_GC_UnTrack'
进行ndefined引用fib.o:fib.c :(。text + 0x1d5b):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :(。text + 0x1d63):未定义的对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :(。text + 0x1d6d):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :( .text + 0x1e91):未定义的对`_imp__PyCode_New'的引用
fib.o:fib.c :(。text + 0x1ee1):未定义的对_imp__PyTuple_Pack'的引用
fib.o:fib.c :(。text + 0x1f31):未定义的引用'_imp__PyTuple_Pack'
fib.o:fib.c :(。text + 0x1fd2):未定义的引用'_imp__PyTuple_Pack'
fib.o:fib.c :(。text + 0x20a4):未定义对`_imp__PyCode_New'的引用
fib.o:fib.c :(。text + 0x2185):未定义对`_imp__PyTuple_New'的引用
fib.o:fib.c :(。text + 0x21cc):对`_imp__PyString_FromStringAndSize'的未定义引用
fib.o:fib.c :(。text + 0x224f):未定义对`_imp__Py_InitModule4'的引用
fib.o:fib.c :(。text + 0x22a4):对_imp_的未定义引用_PyModule_GetDict'
fib.o:fib.c :(。text + 0x22ef):未定义对`_imp__PyImport_AddModule'的引用
fib.o:fib.c :( .text + 0x2341):undefined指向` _imp__PyObject_SetAttrString'
fib.o:fib.c :(。text + 0x23ae):未定义对`_imp__PyObject_SetAttrString'的引用
fib.o:fib.c :( .text + 0x2423) _imp__PyType_Ready'
fib.o:fib.c :(。text + 0x24bf):未定义对`_imp__PyDict_SetItem'的引用
fib.o:fib.c :( .text + 0x252b):undefined指向` _imp__PyCFunction_NewEx'
fib.o:fib.c :(。text + 0x2577):未定义对`_imp__PyDict_SetItem'的引用
fib.o:fib.c :( .text + 0x25cb):未定义引用` _imp__PyDict_New'
fib.o:fib.c :(。text + 0x2614):未定义对`_imp__PyDict_SetItem'的引用
fib.o:fib.c :( .text + 0x26fe):未定义引用` _imp__PyErr_Occurred'
fib.o:fib.c :(。text + 0x2709):未定义对`_imp__PyExc_ImportError'的引用
fib.o:fib.c :( .text + 0x271b):未定义引用` _imp__PyErr (.text + 0x276c):未定义引用`_imp__PyExc_NameError'
fib.o:fib.c :(。text + 0x276c):未定义引用` _imp__PyErr_Format'
fib.o:fib.c :(。text + 0x278d):未定义对`_imp__PyDict_GetItem'的引用
fib.o:fib.c :( .text + 0x27fb):undefined指向` _imp__PyObject_Call'
fib.o:fib.c :(。text + 0x2807):未定义对`_imp___PyThreadState_Current'的引用
fib.o:fib.c :( .text + 0x281a):未定义引用` _imp___Py_CheckRecursionLimit'
fib.o:fib.c :(。text + 0x2834):未定义对`_imp___Py_CheckRecursiveCall'的引用
fib.o:fib.c :( .text + 0x286a):未定义引用` _imp___PyThreadState_Current'
fib.o:fib.c :( .text + 0x2888):对`_imp__PyErr_Occurred'的未定义引用
fib.o:fib.c :( .text + 0x289b):未定义引用` _imp__PyExc_SystemError'
fib.o:fib.c :(。text + 0x28ad):未定义对`_imp__PyErr_SetString'的引用
fib.o:fib.c :( .text + 0x28d4) _im $ _ $ b $ fib.o:fib.c :(。text + 0x28e7):未定义对`_imp___Py_CheckRecursionLimit'的引用
fib.o:fib.c :( .text + 0x2901) _imp___Py_CheckRecursiveCall'
fib.o:fib.c :(。text + 0x2930):对`_imp___PyThreadState_Current'的未定义引用
fib.o:fib.c :( .text + 0x294e):未定义引用` _imp__PyErr_Occurred'
fib.o:fib.c :(。text + 0x2961):未定义对`_imp__PyExc_SystemError'的引用
fib.o:fib.c :( .text + 0x2973) _imp__PyErr_SetString'
fib.o:fib.c :(。text + 0x298c):未定义对`_imp__PyTuple_New'的引用
fib.o:fib.c :( .text + 0x2a16):未定义引用` _imp__PyCFunction_Type'
fib.o:fib.c :(。text + 0x2a51):未定义对`_imp__PyType_IsSubtype'的引用
fib.o:fib.c :(。text + 0x2ac8):未定义引用` _imp__PyImport_AddModule'
fib.o:fib.c :( .text + 0x2aff):对_imp__PyObject_GetAttrString的未定义引用
fib.o:fib.c :( .text + 0x2b22):undef ('text + 0x2b38):未定义的引用'_imp__PyErr_Format'
fib.o:fib.c :(。text + 0x2b5e):引用`_imp__PyExc_TypeError'
fib.o:fib.c :(。对`_imp__PyExc_TypeError'的未定义引用
fib.o:fib.c :(。text + 0x2b74):未定义对`_imp__PyErr_Format'的引用
fib.o:fib.c :(。text + 0x2b80):未定义的对`_imp__PyExc_AttributeError'的引用
fib.o:fib.c :(。text + 0x2b8a):对`_imp__PyErr_ExceptionMatches'的未定义引用
fib.o:fib.c :(。text + 0x2b97):未定义对`_imp__PyErr_Clear'的引用
fib.o:fib.c :(。text + 0x2ba4):对`_imp__PyType_Ready'的未定义引用
fib.o:fib.c :(。text + 0x2bc8):未定义的对`_imp__PyObject_SetAttrString'的引用
fib.o:fib.c :(。text + 0x2c7d):对`_imp__PyString_FromString'的未定义引用
fib.o:fib.c :(。text + 0x2ca5):未定义的对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :(。text + 0x2caf):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :( .text + 0x2cb6): undefined ref参考`_imp___Py_NoneStruct'
fib.o:fib.c :(。text + 0x2ce7):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :(。text + 0x2d5c):undefined对`_imp__PyString_InternFromString'的引用
fib.o:fib.c :( .text + 0x2dc7):未定义对`_imp__PyExc_TypeError'的引用
fib.o:fib.c :(。text + 0x2dd9):undefined对`_imp__PyErr_SetString'的引用
fib.o:fib.c :(。text + 0x2e80):未定义对`_imp__PyExc_TypeError'的引用
fib.o:fib.c :(。text + 0x2e92):undefined引用'_imp__PyErr_SetString'
fib.o:fib.c :(。text + 0x2f08):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :(。text + 0x2f3a):undefined对`_imp__PyDict_New'的引用
fib.o:fib.c :(。text + 0x2f8b):未定义对`_imp__PyExc_TypeError'的引用
fib.o:fib.c :(。text + 0x2f9d):undefined引用'_imp__PyErr_SetString'
fib.o:fib.c :(。text + 0x2fc8):未定义对`_imp__PyExc_TypeError'的引用
fib.o:fib.c :(。text + 0x2fda):undefined引用`_im p__PyErr_SetString'
fib.o:fib.c :( .text + 0x3056):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :( .text + 0x3060):未定义引用` _imp___Py_NoneStruct'
fib.o:fib.c :(。text + 0x3067):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :( .text + 0x3086) _imp___Py_NoneStruct'
fib.o:fib.c :(。text + 0x313d):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :( .text + 0x3147):更多未定义的引用`_imp___Py_NoneStruct'后面跟着
fib.o:fib.c :(。text + 0x3163):未定义引用'_imp__PyExc_TypeError'
fib.o:fib.c :( .text + 0x3175):undefined reference ('text + 0x321e):未定义引用'_imp___Py_NoneStruct'
fib.o:fib.c :(。text + 0x3244):未定义的引用到`_imp___Py_NoneStruct'
fib.o:fib.c :(。text + 0x324e):对`_imp___Py_NoneStruct'的未定义引用
fib.o:fib.c :( .text + 0x326a):undefined reference到`_imp__PyExc_Typ eError'
fib.o:fib.c :( .text + 0x327c):未定义对`_imp__PyErr_SetString'的引用
fib.o:fib.c :( .text + 0x3325):未定义引用` _imp___Py_NoneStruct'
fib.o:fib.c :( .text + 0x334b):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :( .text + 0x3370):undefined指向` _imp__PyExc_TypeError'
fib.o:fib.c :( .text + 0x3382):未定义对`_imp__PyErr_SetString'的引用
fib.o:fib.c :( .text + 0x3406):undefined指向` _imp__PyDict_New'
fib.o:fib.c :(。text + 0x3451):未定义对`_imp__PyString_FromString'的引用
fib.o:fib.c :( .text + 0x3466):undefined指向` _imp___PyObject_GC_New'
fib.o:fib.c :(。text + 0x358f):未定义对`_imp__PyObject_GC_Track'的引用
fib.o:fib.c :( .text + 0x3969) _imp__PyMem_Free'
fib.o:fib.c :( .text + 0x398d):未定义对`_imp__PyObject_GC_UnTrack'的引用
fib.o:fib.c :( .text + 0x39a4):undefined指向` _imp__PyObject_ClearWeakRefs'
fib.o:fib.c :(。text + 0x39bc):未定义对`_imp__PyObject_GC_Del'的引用
fib.o:fib.c :( .text + 0x3cab):未定义引用'_imp__PyMethod_New'
fib.o:fib.c :(。text + 0x3cb4):未定义引用_imp__Py_NoneStruct'
fib.o:fib.c :( .text + 0x3cd9):未定义引用'_imp__PyMethod_New'
fib.o:fib.c :(。text + 0x3cf1):未定义对`_imp__PyString_AsString'的引用
fib.o:fib.c :( .text + 0x3d0c):未定义引用'_imp__PyString_FromFormat'
fib.o:fib.c :(。text + 0x3d2f):未定义对`_imp__PyCFunction_Call'的引用
fib.o:fib.c :( .text + 0x3d3e):未定义对`_imp__PyCFunction_Call'
fib.o:fib.c :( .text + 0x3d7c):未定义对`_imp__PyCFunction_Type'的引用
fib.o:fib.c :( .text + 0x3db7):未定义引用'_imp__PyType_IsSubtype'
fib.o:fib.c :(。text + 0x3e81):未定义对`_imp__PyList_New'的引用
fib.o:fib.c :(。text + 0x3ea4):未定义对`_imp__PyModule_GetDict'
fib.o:fib.c: (.text + 0x3eb9):对`_imp__PyDict_New'的未定义引用
fib.o:fib.c :(。text + 0x3eda):对`_imp__PyInt_FromLong'的未定义引用
fib.o:fib.c: (.text + 0x3f1d):对_imp__PyObject_CallFunctionObjArgs的未定义引用
fib.o:fib.c :( .text + 0x4182):对_imp__PyMem_Malloc的未定义引用
fib.o:fib.c: (.text + 0x42b0):对`_imp__PyMem_Realloc'的未定义引用
fib.o:fib.c :( .text + 0x438a):对`_imp__PyString_FromString'的未定义引用
fib.o:fib.c: (.text + 0x43c3):对`_imp__PyString_FromFormat'的未定义引用
fib.o:fib.c :( .text + 0x43d5):对`_imp__PyString_FromString'的未定义引用
fib.o:fib.c: (.text + 0x4469):对`_imp__PyCode_New'的未定义引用
fib.o:fib.c :( .text + 0x45ae):对`_imp___PyThreadState_Current'的未定义引用
fib.o:fib.c: (.text + 0x45cb):`_imp__PyFrame_New'的未定义引用
fib.o:fib.c :( .text + 0x45ec):对`_imp__PyTraceBack_Here'的未定义引用
fib.o:fib.c: (.T ext + 0x465c):'_imp__PySys_GetObject'的未定义引用
fib.o:fib.c :( .text + 0x466c):未定义对`_imp__PyExc_RuntimeError'的引用
fib.o:fib.c :(。文本+ 0x467e):对`_imp__PyErr_SetString'的未定义引用
fib.o:fib.c :(。text + 0x46d5):未定义对`_imp__PyFile_SoftSpace'的引用
fib.o:fib.c :(。文本+ 0x46ee):对`_imp__PyFile_WriteString'的未定义引用
fib.o:fib.c :(。text + 0x4720):未定义对`_imp__PyFile_WriteObject'的引用
fib.o:fib.c :(。文本+ 0x4748):对`_imp__PyString_AsString'的未定义引用
fib.o:fib.c :( .text + 0x4758):未定义对`_imp__PyString_Size'的引用
fib.o:fib.c :(。文本+ 0x4798):对`_imp__PyFile_SoftSpace'的未定义引用
fib.o:fib.c :( .text + 0x47cc):未定义对`_imp__PyFile_WriteString'的引用
fib.o:fib.c :(。文本+ 0x47e7):未定义的引用'_imp__PyFile_SoftSpace'
fib.o:fib.c :(。text + 0x4889):未定义的引用'_imp__PyFile_SoftSpace'
fib.o:fib.c :(。 Ť ext + 0x48a2):未定义引用`_imp__PyFile_WriteString'
fib.o:fib.c :( .text + 0x48c4):未定义的引用'_imp__PyFile_WriteObject'
fib.o:fib.c :(。文本+ 0x48df):未定义引用`_imp__PyFile_WriteString'
fib.o:fib.c :(。text + 0x4977):未定义对`_imp__PyOS_snprintf'的引用
fib.o:fib.c :(。文本+ 0x497e):对`_imp__Py_GetVersion'的未定义引用
fib.o:fib.c :(。text + 0x499f):未定义对`_imp__PyOS_snprintf'的引用
fib.o:fib.c :(。文本+ 0x49ed):对`_imp__PyOS_snprintf'的未定义引用
fib.o:fib.c :(。text + 0x4a0d):未定义对`_imp__PyErr_WarnEx'的引用
fib.o:fib.c :(。文本+ 0x4a57):对`_imp__PyUnicodeUCS2_DecodeUTF8'的未定义引用
fib.o:fib.c :(。text + 0x4a7b):未定义对`_imp__PyString_InternFromString'的引用
fib.o:fib.c :(。文本+ 0x4aa1):未定义的引用`_imp__PyString_FromStringAndSize'
fib.o:fib.c :(。text + 0x4afe):未定义的引用'_imp__PyByteArray_Type'
fi bo:fib.c :( .text + 0x4b0e):未定义引用'_imp__PyByteArray_Type'
fib.o:fib.c :( .text + 0x4b1a):未定义引用'_imp__PyType_IsSubtype'
fib。 o:fib.c :( .text + 0x4b2f):对`_imp__PyByteArray_Type'的未定义引用
fib.o:fib.c :( .text + 0x4b3f):未定义对`_imp__PyByteArray_Type'的引用
fib。 o:fib.c :( .text + 0x4b4b):对`_imp__PyType_IsSubtype'的未定义引用
fib.o:fib.c :( .text + 0x4b83):未定义对`_imp__PyByteArray_Type'的引用
fib。 o:fib.c :( .text + 0x4b93):对'_imp__PyByteArray_Type'的未定义引用
fib.o:fib.c :( .text + 0x4b9f):对`_imp__PyType_IsSubtype'
fib的未定义引用。 o:fib.c :( .text + 0x4bd8):对`_imp___PyByteArray_empty_string'的未定义引用
fib.o:fib.c :( .text + 0x4bf3):未定义对`_imp__PyString_AsStringAndSize'的引用
fib。 o:fib.c :( .text + 0x4c1c):对`_imp___Py_TrueStruct'的未定义引用
fib.o:fib.c :( .text + 0x4c2d):对_imp___Py_ZeroStruct的未定义引用
fib.o:fib.c :( .text + 0x4c40):未定义对`_imp___Py_NoneStruct'的引用
fib.o:fib.c :( .text + 0x4c5f):未定义引用'_imp__PyObject_IsTrue'
collect2.exe:error:ld返回1退出状态

我将不胜感激任何帮助。

解决方案

我总是用一行gcc编译我的cython:

gcc -shared -Wall -O3 -I Python27 / include -L Python27 / libs -o fib.so fib.c -l python27



你看,包括python头文件(-I)是不够的。您还必须包含python库的位置(-L),然后包含用作该库的文件的名称(-l)。

快乐Cythonizing!

I've just started to learn cython and this is the first time that I'm trying to compile .pyx files.I tried to run in my cmd:

which gave me my fib.c file.

then I run:

which gave me my fib.o file, but when I tried to

it gave me this exception:

fib.o:fib.c:(.text+0x72): undefined reference to `_imp__PyObject_GetAttr'
fib.o:fib.c:(.text+0xdb): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x26c): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x2ae): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0x31c): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x418): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x53b): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x543): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x54d): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x79d): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0x874): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0x88b): undefined reference to `_imp__PyTuple_Type'
fib.o:fib.c:(.text+0x8c4): undefined reference to `_imp__PyObject_GetIter'
fib.o:fib.c:(.text+0x972): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0xa0b): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0xa1b): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0xa2f): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0xa40): undefined reference to `_imp__PyErr_GivenExceptionMatches'
fib.o:fib.c:(.text+0xa53): undefined reference to `_imp__PyErr_Clear'
fib.o:fib.c:(.text+0xac3): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0xcec): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0xd2e): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0xd96): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0xe9e): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0xee0): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0xf48): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x107c): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x11d9): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0x11f0): undefined reference to `_imp__PyTuple_Type'
fib.o:fib.c:(.text+0x1229): undefined reference to `_imp__PyObject_GetIter'
fib.o:fib.c:(.text+0x12d7): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0x1370): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x1380): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0x1394): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0x13a5): undefined reference to `_imp__PyErr_GivenExceptionMatches'
fib.o:fib.c:(.text+0x13b8): undefined reference to `_imp__PyErr_Clear'
fib.o:fib.c:(.text+0x1472): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x153f): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x183e): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x19c0): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x19c8): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x19d2): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1c16): undefined reference to `_imp__PyObject_GC_Track'
fib.o:fib.c:(.text+0x1c67): undefined reference to `_imp__PyObject_GC_UnTrack'
fib.o:fib.c:(.text+0x1d5b): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1d63): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1d6d): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1e91): undefined reference to `_imp__PyCode_New'
fib.o:fib.c:(.text+0x1ee1): undefined reference to `_imp__PyTuple_Pack'
fib.o:fib.c:(.text+0x1f31): undefined reference to `_imp__PyTuple_Pack'
fib.o:fib.c:(.text+0x1fd2): undefined reference to `_imp__PyTuple_Pack'
fib.o:fib.c:(.text+0x20a4): undefined reference to `_imp__PyCode_New'
fib.o:fib.c:(.text+0x2185): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x21cc): undefined reference to `_imp__PyString_FromStringAndSize'
fib.o:fib.c:(.text+0x224f): undefined reference to `_imp__Py_InitModule4'
fib.o:fib.c:(.text+0x22a4): undefined reference to `_imp__PyModule_GetDict'
fib.o:fib.c:(.text+0x22ef): undefined reference to `_imp__PyImport_AddModule'
fib.o:fib.c:(.text+0x2341): undefined reference to `_imp__PyObject_SetAttrString'
fib.o:fib.c:(.text+0x23ae): undefined reference to `_imp__PyObject_SetAttrString'
fib.o:fib.c:(.text+0x2423): undefined reference to `_imp__PyType_Ready'
fib.o:fib.c:(.text+0x24bf): undefined reference to `_imp__PyDict_SetItem'
fib.o:fib.c:(.text+0x252b): undefined reference to `_imp__PyCFunction_NewEx'
fib.o:fib.c:(.text+0x2577): undefined reference to `_imp__PyDict_SetItem'
fib.o:fib.c:(.text+0x25cb): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x2614): undefined reference to `_imp__PyDict_SetItem'
fib.o:fib.c:(.text+0x26fe): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x2709): undefined reference to `_imp__PyExc_ImportError'
fib.o:fib.c:(.text+0x271b): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2756): undefined reference to `_imp__PyExc_NameError'
fib.o:fib.c:(.text+0x276c): undefined reference to `_imp__PyErr_Format'
fib.o:fib.c:(.text+0x278d): undefined reference to `_imp__PyDict_GetItem'
fib.o:fib.c:(.text+0x27fb): undefined reference to `_imp__PyObject_Call'
fib.o:fib.c:(.text+0x2807): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x281a): undefined reference to `_imp___Py_CheckRecursionLimit'
fib.o:fib.c:(.text+0x2834): undefined reference to `_imp___Py_CheckRecursiveCall'
fib.o:fib.c:(.text+0x286a): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x2888): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x289b): undefined reference to `_imp__PyExc_SystemError'
fib.o:fib.c:(.text+0x28ad): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x28d4): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x28e7): undefined reference to `_imp___Py_CheckRecursionLimit'
fib.o:fib.c:(.text+0x2901): undefined reference to `_imp___Py_CheckRecursiveCall'
fib.o:fib.c:(.text+0x2930): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x294e): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x2961): undefined reference to `_imp__PyExc_SystemError'
fib.o:fib.c:(.text+0x2973): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x298c): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x2a16): undefined reference to `_imp__PyCFunction_Type'
fib.o:fib.c:(.text+0x2a51): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x2ac8): undefined reference to `_imp__PyImport_AddModule'
fib.o:fib.c:(.text+0x2aff): undefined reference to `_imp__PyObject_GetAttrString'
fib.o:fib.c:(.text+0x2b22): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2b38): undefined reference to `_imp__PyErr_Format'
fib.o:fib.c:(.text+0x2b5e): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2b74): undefined reference to `_imp__PyErr_Format'
fib.o:fib.c:(.text+0x2b80): undefined reference to `_imp__PyExc_AttributeError'
fib.o:fib.c:(.text+0x2b8a): undefined reference to `_imp__PyErr_ExceptionMatches'
fib.o:fib.c:(.text+0x2b97): undefined reference to `_imp__PyErr_Clear'
fib.o:fib.c:(.text+0x2ba4): undefined reference to `_imp__PyType_Ready'
fib.o:fib.c:(.text+0x2bc8): undefined reference to `_imp__PyObject_SetAttrString'
fib.o:fib.c:(.text+0x2c7d): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x2ca5): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2caf): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2cb6): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2ce7): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2d5c): undefined reference to `_imp__PyString_InternFromString'
fib.o:fib.c:(.text+0x2dc7): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2dd9): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2e80): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2e92): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2f08): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2f3a): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x2f8b): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2f9d): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2fc8): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2fda): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x3056): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3060): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3067): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3086): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x313d): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3147): more undefined references to `_imp___Py_NoneStruct' follow
fib.o:fib.c:(.text+0x3163): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x3175): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x321e): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3244): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x324e): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x326a): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x327c): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x3325): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x334b): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3370): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x3382): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x3406): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x3451): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x3466): undefined reference to `_imp___PyObject_GC_New'
fib.o:fib.c:(.text+0x358f): undefined reference to `_imp__PyObject_GC_Track'
fib.o:fib.c:(.text+0x3969): undefined reference to `_imp__PyMem_Free'
fib.o:fib.c:(.text+0x398d): undefined reference to `_imp__PyObject_GC_UnTrack'
fib.o:fib.c:(.text+0x39a4): undefined reference to `_imp__PyObject_ClearWeakRefs'
fib.o:fib.c:(.text+0x39bc): undefined reference to `_imp__PyObject_GC_Del'
fib.o:fib.c:(.text+0x3cab): undefined reference to `_imp__PyMethod_New'
fib.o:fib.c:(.text+0x3cb4): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3cd9): undefined reference to `_imp__PyMethod_New'
fib.o:fib.c:(.text+0x3cf1): undefined reference to `_imp__PyString_AsString'
fib.o:fib.c:(.text+0x3d0c): undefined reference to `_imp__PyString_FromFormat'
fib.o:fib.c:(.text+0x3d2f): undefined reference to `_imp__PyCFunction_Call'
fib.o:fib.c:(.text+0x3d3e): undefined reference to `_imp__PyCFunction_Call'
fib.o:fib.c:(.text+0x3d7c): undefined reference to `_imp__PyCFunction_Type'
fib.o:fib.c:(.text+0x3db7): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x3e81): undefined reference to `_imp__PyList_New'
fib.o:fib.c:(.text+0x3ea4): undefined reference to `_imp__PyModule_GetDict'
fib.o:fib.c:(.text+0x3eb9): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x3eda): undefined reference to `_imp__PyInt_FromLong'
fib.o:fib.c:(.text+0x3f1d): undefined reference to `_imp__PyObject_CallFunctionObjArgs'
fib.o:fib.c:(.text+0x4182): undefined reference to `_imp__PyMem_Malloc'
fib.o:fib.c:(.text+0x42b0): undefined reference to `_imp__PyMem_Realloc'
fib.o:fib.c:(.text+0x438a): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x43c3): undefined reference to `_imp__PyString_FromFormat'
fib.o:fib.c:(.text+0x43d5): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x4469): undefined reference to `_imp__PyCode_New'
fib.o:fib.c:(.text+0x45ae): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x45cb): undefined reference to `_imp__PyFrame_New'
fib.o:fib.c:(.text+0x45ec): undefined reference to `_imp__PyTraceBack_Here'
fib.o:fib.c:(.text+0x465c): undefined reference to `_imp__PySys_GetObject'
fib.o:fib.c:(.text+0x466c): undefined reference to `_imp__PyExc_RuntimeError'
fib.o:fib.c:(.text+0x467e): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x46d5): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x46ee): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x4720): undefined reference to `_imp__PyFile_WriteObject'
fib.o:fib.c:(.text+0x4748): undefined reference to `_imp__PyString_AsString'
fib.o:fib.c:(.text+0x4758): undefined reference to `_imp__PyString_Size'
fib.o:fib.c:(.text+0x4798): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x47cc): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x47e7): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x4889): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x48a2): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x48c4): undefined reference to `_imp__PyFile_WriteObject'
fib.o:fib.c:(.text+0x48df): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x4977): undefined reference to `_imp__PyOS_snprintf'
fib.o:fib.c:(.text+0x497e): undefined reference to `_imp__Py_GetVersion'
fib.o:fib.c:(.text+0x499f): undefined reference to `_imp__PyOS_snprintf'
fib.o:fib.c:(.text+0x49ed): undefined reference to `_imp__PyOS_snprintf'
fib.o:fib.c:(.text+0x4a0d): undefined reference to `_imp__PyErr_WarnEx'
fib.o:fib.c:(.text+0x4a57): undefined reference to `_imp__PyUnicodeUCS2_DecodeUTF8'
fib.o:fib.c:(.text+0x4a7b): undefined reference to `_imp__PyString_InternFromString'
fib.o:fib.c:(.text+0x4aa1): undefined reference to `_imp__PyString_FromStringAndSize'
fib.o:fib.c:(.text+0x4afe): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b0e): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b1a): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x4b2f): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b3f): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b4b): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x4b83): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b93): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b9f): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x4bd8): undefined reference to `_imp___PyByteArray_empty_string'
fib.o:fib.c:(.text+0x4bf3): undefined reference to `_imp__PyString_AsStringAndSize'
fib.o:fib.c:(.text+0x4c1c): undefined reference to `_imp___Py_TrueStruct'
fib.o:fib.c:(.text+0x4c2d): undefined reference to `_imp___Py_ZeroStruct'
fib.o:fib.c:(.text+0x4c40): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x4c5f): undefined reference to `_imp__PyObject_IsTrue'
collect2.exe: error: ld returned 1 exit status

I'll be grateful for any help.

解决方案

I always compile my cython with one line of gcc:

gcc -shared -Wall -O3 -I Python27/include -L Python27/libs -o fib.so fib.c -l python27

You see, including the header files (-I) for python isn't enough. You also have to include the location of python's libraries (-L), and then the name of the file to use as that library (-l).

Happy Cythonizing!

这篇关于编译pyx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 20:20