Comstackr des fichiers pyx

Je viens de commencer à apprendre le cython et c’est la première fois que j’essaie de comstackr des fichiers .pyx. J’ai essayé de courir dans mon cmd:

Fib.pyx en Cython

qui m’a donné mon fichier fib.c.

alors je cours:

gcc -c fib.c -I / Python27 / include

qui m’a donné mon fichier fib.o, mais quand j’ai essayé de

gcc -shared fib.o -o fib.so

cela m’a donné cette 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__PySsortingng_FromSsortingng' 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__PySsortingng_FromSsortingng' 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__PySsortingng_FromSsortingng' 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__PySsortingng_FromSsortingngAndSize' 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_SetAttrSsortingng' fib.o:fib.c:(.text+0x23ae): undefined reference to `_imp__PyObject_SetAttrSsortingng' 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_SetSsortingng' 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_SetSsortingng' 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_SetSsortingng' 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_GetAttrSsortingng' 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_AtsortingbuteError' 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_SetAttrSsortingng' fib.o:fib.c:(.text+0x2c7d): undefined reference to `_imp__PySsortingng_FromSsortingng' 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__PySsortingng_InternFromSsortingng' fib.o:fib.c:(.text+0x2dc7): undefined reference to `_imp__PyExc_TypeError' fib.o:fib.c:(.text+0x2dd9): undefined reference to `_imp__PyErr_SetSsortingng' fib.o:fib.c:(.text+0x2e80): undefined reference to `_imp__PyExc_TypeError' fib.o:fib.c:(.text+0x2e92): undefined reference to `_imp__PyErr_SetSsortingng' 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_SetSsortingng' fib.o:fib.c:(.text+0x2fc8): undefined reference to `_imp__PyExc_TypeError' fib.o:fib.c:(.text+0x2fda): undefined reference to `_imp__PyErr_SetSsortingng' 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_SetSsortingng' 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_SetSsortingng' 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_SetSsortingng' fib.o:fib.c:(.text+0x3406): undefined reference to `_imp__PyDict_New' fib.o:fib.c:(.text+0x3451): undefined reference to `_imp__PySsortingng_FromSsortingng' 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__PySsortingng_AsSsortingng' fib.o:fib.c:(.text+0x3d0c): undefined reference to `_imp__PySsortingng_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__PySsortingng_FromSsortingng' fib.o:fib.c:(.text+0x43c3): undefined reference to `_imp__PySsortingng_FromFormat' fib.o:fib.c:(.text+0x43d5): undefined reference to `_imp__PySsortingng_FromSsortingng' 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_SetSsortingng' fib.o:fib.c:(.text+0x46d5): undefined reference to `_imp__PyFile_SoftSpace' fib.o:fib.c:(.text+0x46ee): undefined reference to `_imp__PyFile_WriteSsortingng' fib.o:fib.c:(.text+0x4720): undefined reference to `_imp__PyFile_WriteObject' fib.o:fib.c:(.text+0x4748): undefined reference to `_imp__PySsortingng_AsSsortingng' fib.o:fib.c:(.text+0x4758): undefined reference to `_imp__PySsortingng_Size' fib.o:fib.c:(.text+0x4798): undefined reference to `_imp__PyFile_SoftSpace' fib.o:fib.c:(.text+0x47cc): undefined reference to `_imp__PyFile_WriteSsortingng' 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_WriteSsortingng' fib.o:fib.c:(.text+0x48c4): undefined reference to `_imp__PyFile_WriteObject' fib.o:fib.c:(.text+0x48df): undefined reference to `_imp__PyFile_WriteSsortingng' 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__PySsortingng_InternFromSsortingng' fib.o:fib.c:(.text+0x4aa1): undefined reference to `_imp__PySsortingng_FromSsortingngAndSize' 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_ssortingng' fib.o:fib.c:(.text+0x4bf3): undefined reference to `_imp__PySsortingng_AsSsortingngAndSize' 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 

Je serai reconnaissant pour toute aide.

Je comstack toujours mon cython avec une ligne de gcc:

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

Vous voyez, y compris les fichiers d’en-tête (-I) pour Python ne suffit pas. Vous devez également inclure l’emplacement des bibliothèques de python (-L), puis le nom du fichier à utiliser en tant que bibliothèque (-l).

Joyeux Cythonisant!

Il existe une autre solution qui pourrait être utile avec des projets plus importants. Au lieu d’écrire vous-même l’appel gcc dans la ligne de commande, vous pouvez créer un fichier de configuration en python que cython utilisera pour générer automatiquement du code C ou C ++ et appeler le compilateur gcc avec les indicateurs appropriés.

Créez simplement un fichier setup.py (ou un nom de fichier de votre setup.py ). Puis remplissez-le avec:

 from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize ext = Extension("fib", sources=["fib.pyx"], language="c++", include_dirs=[], libraries=[], extra_link_args=[]) setup(ext_modules = cythonize([ext])) 

Ensuite, dans le terminal python setup.py build_ext --inplace .

Cela générera un fichier fib.cpp et le comstackra dans le fichier object partagé fib.so ainsi qu’un fichier object fib.o (ce dernier dans un dossier appelé build ). Après cela, vous pouvez déjà import fib fichiers import fib dans vos fichiers *.py .