So I have a few Python C extensions I have previously built for and used in 32 bit Python running in Win7. I have now however switched to 64 bit Python, and I am having issues building the C extension with MinGW-w64.
I made the changes to distutils as per this post, but I am getting some weird errors suggesting something is wrong:
$ 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
I have googled around quite a bit to find information, but it's not easy to find a definite answer. Could someone shed some light on this? What further changes should I do to be able to successfully build C extensions for 64 bit Python in Win7?
EDIT:
After some helpful pointers in cgohlke's comments below I managed to generate libpython27.a
. However after following the advice on this post (2nd to last) I still had a the __imp_Py_InitModule4_64
error. After some serious Google-fu I managed to trip over this post telling me to rename the Py_InitModule4
line to Py_InitModule4_64
. After that everything worked swimmingly.
libpython27.a
withgendef.exe python27.dll
anddlltool.exe --dllname python27.dll --def python27.def --output-lib libpython27.a
and place it inC:\Python27\libs
– WrathTraceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: DLL load failed: The specified procedure could not be found.
I think somewhere I must be missing a file. The only thing I did with the gendef stuff was to putlibpython27.a
inC:\Python27\libs
. Did I miss something? – Cariboubuild\temp.win-amd64-2.7\Release\cquant.o:cQuant.c:(.text+0x1f09): undefined reference to
__imp_Py_InitModule4_64' collect2.exe: error: ld returned 1 exit status` – Caribou-DMS_WIN64
flag too, but I still get the error. I don't really understand why it should be so hard to compile to 64 bit Python when 32 bit is very simple and straightforward. Thanks for the help though, much appreciated. – CaribouPy_InitModule4
line toPy_InitModule4_64
in thepython27.def
file. Thanks a lot for the help. If you happen to be the cgohlke behind this site, thanks for that one too, those binaries have been a huge help from time to time :) – Caribousetenv /release /x64
,set DISTUTILS_USE_SDK=1
,set MSSdk=1
andpip install blah
or the install method of your choice. – FactfindingVisual C++ 2008
didn't like (C99 related I think). Ordinarily I would just change the code, but the same code is used on a Linux box as well. So long story short I set the mingw-w64 environment up instead so that I could have the same code base throughout. – Caribou