Building extensions with MinGW on Win2K - formerly "Extension module import error with MinGW, SWIG, and distutils"

Phil Schmidt pschmidt at omnimn.com
Tue Aug 13 16:15:13 EDT 2002


I finally got things working, at least, without SWIG, which is ok for
now. Baby steps!

Surprisingly, a colleague of mine did not have to go through the
gyrations I did. He simply downloaded MinGW, and was able to create
extensions right away. One difference is that he does not have Cygwin
installed, and I do, so it could be that I was accidentally using some
of the Cygwin tools, instead of the MinGW tools. (This is something I
should investigate further...)


Anyway, here's a summary of what I had to do to be able to build
Python extensions on a Win2K machine using MinGW.

1) Download (from http://prdownloads.sourceforge.net/mingw/MinGW-1.1.tar.gz?download)
and install MinGW. I put MinGW in c:\Mingw.

2) Download Paul Sokolovsky's altbinutils-pe 1_0 zipfile. Unzip it,
and put the contents of the \bin directory into your MinGW\bin
directory. This gets pexports.exe, which you need to create the .def
file for python22.dll. See
http://www.cygwin.com/ml/cygwin/2001-05/msg01412.html and
http://prdownloads.sourceforge.net/mingwrep/altbinutils-pe-1.0.zip?download
.

3) Create the import library libpython22.a. You can do this manually,
or use the script described by Mike Fletcher
(http://groups.google.com/groups?q=schmidt+group:comp.lang.python.*&hl=en&lr=&ie=UTF-8&scoring=d&selm=mailman.1028918486.23281.python-list%40python.org&rnum=1).

To do it manually, type the following two commands. Be sure that your
path points to the MinGW\bin directory, so that pexports and dlltool
run from there. (Change the Python path in the commands to match your
installation too.)

pexports c:\winnt\system32\python22.dll >
C:\PROGRA~1\PYTHON22\libs\python22.def
dlltool -d C:\PROGRA~1\PYTHON22\libs\python22.def -l
C:\PROGRA~1\PYTHON22\libs\libpython22.a

4) Run distutils to build the module.



More information about the Python-list mailing list