Así que tengo unas pocas extensiones de Python C que he creado previamente y que utilizo en Python de 32 bits en Win7. Sin embargo, ahora he cambiado a Python de 64 bits, y tengo problemas para construir la extensión C con MinGW-w64.¿Cómo puedo construir mis extensiones C con MinGW-w64 en Python?
que realizó los cambios en distutils como por this post, pero yo estoy haciendo algunos errores extraños que sugiere que algo está mal:
$ python setup.py build
running build
running build_ext
building 'MyLib' extension
c:\MinGW64\bin\x86_64-w64-mingw32-gcc.exe -mdll -O -Wall -Ic:\Python27\lib\site-packages\numpy\core\include -Ic:\Python27\include -Ic:\Python27\PC -c MyLib.c -o build\temp.win-amd64-2.7\Release\mylib.o
MyLib.c: In function 'initMyLib':
MyLib.c:631:5: warning: implicit declaration of function 'Py_InitModule4_64' [-Wimplicit-function-declaration]
writing build\temp.win-amd64-2.7\Release\MyLib.def
c:\MinGW64\bin\x86_64-w64-mingw32-gcc.exe -shared -s build\temp.win-amd64-2.7\Release\mylib.o build\temp.win-amd64-2.7\Release\MyLib.def -Lc:\Python27\libs -Lc:\Python27\PCbuild\amd64 -lpython27 -o build\lib.win-amd64-2.7\MyLib.pyd
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x13d): undefined reference to `__imp_PyExc_ValueError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1275): undefined reference to `__imp_PyExc_ValueError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1eef): undefined reference to `__imp_PyExc_ImportError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1f38): undefined reference to `__imp_PyExc_AttributeError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1f4d): undefined reference to `__imp_PyCObject_Type'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1f61): undefined reference to `__imp_PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1fc7): undefined reference to `__imp_PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x1ffe): undefined reference to `__imp_PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x2042): undefined reference to `__imp_PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x206c): undefined reference to `__imp_PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x208a): more undefined references to `__imp_PyExc_RuntimeError' follow
build\temp.win-amd64-2.7\Release\mylib.o:MyLib.c:(.text+0x20a7): undefined reference to `__imp_PyExc_ImportError'
collect2.exe: error: ld returned 1 exit status
error: command 'x86_64-w64-mingw32-gcc' failed with exit status 1
He buscado en Google todo un poco para encontrar información, pero no es fácil de encontrar una respuesta definitiva. ¿Alguien podría arrojar algo de luz sobre esto? ¿Qué más cambios debería hacer para poder crear correctamente extensiones C para Python de 64 bits en Win7?
EDIT:
Después de algunos consejos útiles en los comentarios de abajo cgohlke que logró generar libpython27.a
. Sin embargo, después de seguir el consejo en this post (penúltimo a último), todavía tenía el error __imp_Py_InitModule4_64
. Después de un serio Google-fu logré tropezar con this post diciéndome que cambie el nombre de la línea Py_InitModule4
al Py_InitModule4_64
. Después de eso, todo funcionó a la perfección.
Necesita crear 'libpython27.a' con' gendef.exe python27.dll' y 'dlltool.exe --dllname python27.dll --def python27.def --output-lib libpython27.a' y colocarlo en 'C: \ Python27 \ libs' – cgohlke
Vi algunas publicaciones mencionando gendef. Pero no es fácil encontrar información sobre cómo generar el archivo libpython27.a. ¿Sabrías saber de alguna? – c00kiemonster
Oh ok, gendef y dlltool son dos comandos diferentes. Intentará. Gracias. – c00kiemonster