SWIG/Python on Windows

Gerhard Häring gh_pythonlist at gmx.de
Fri Nov 2 20:10:16 CET 2001

On Fri, Nov 02, 2001 at 11:47:53AM -0800, DD wrote:
> Has anybody used SWIG with Python on Windows without Microsoft Visual
> C++?  I'm having problems getting the hellolib example in the
> Extending Python chapter from "Programming Python" to compile with
> gcc.  I'm getting undefined reference errors to "Py..." functions, ex:
> PyString_FromString.

> All the examples I can find on the web use MSVC and I can't find an
> example for compiling a DLL using a makefile.

Madness lies down that path. I'd recommend you enter the beautiful land
of Python distutils instead. Building an extension on Windows is
relatively painless then.

First, you need to create an import library for gcc. Have a look at the
HOWTO I posted here in August on how to do this and other useful tips
for developing and debugging on Windows with gcc:


- write a setup.py for it
- "python setup.py build --compiler=mingw32" (or install, or even

As for the SWIG part of your problem, I'd just create the .c and .h
files for setup.py, then use python setup.py to build. I remember having
seen SWIG integration with distutils somewhere, but don't remember

mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

More information about the Python-list mailing list