[Distutils] Building extensions with mingw

Robert Kern kern@caltech.edu
Sat Jul 14 23:26:01 2001


On Sat, Jul 14, 2001 at 05:56:45PM +0100, Paul Moore wrote:
> I have ActiveState Python 2.1 (which I assume was built with MSVC), and I am
> trying to build an extension using the mingw compiler. When I try to build
> (python setup.py build -c mingw32) I get a whole load of undefined references to
> _imp__Py... symbols.
> 
> Presumably, I'm missing some sort of supporting import library to tell mingw
> about Python - the question is, how do I get one? Or am I being naive in
> assuming that I can use mingw to build extensions for a Python built with MSVC?

No, you are not being naive. It is possible and quite easy with the Distutils.
What you need to do is make a mingw import library (python21.lib will not work.)
What I need to do is get some free time to make an import library and tidy up my
page on extending Python via mingw.

Grab http://starship.python.net/crew/kernr/mingw32/lib2def.py
and change all instances of the string "python15" with the string "python21",
and you should be able to run it over python21.lib to get libpython21.a to
link with. It requires the program nm from mingw, so be sure to have that on
your path. You should be able to use the pristine include files.

The script might have to be tweaked a little more to catch all of the symbols.
An (untested) alternative would be to use the pexports program from
http://prdownloads.sourceforge.net/mingwrep/altbinutils-pe-1.0.zip

I haven't used Windows in some time, so I've been lazy about updating
everything.

-- 
Robert Kern
kern@caltech.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter