Sample distutil setup.py script that uses SWIG and C++?

David M. Cooke cookedm+news at physics.mcmaster.ca
Mon Sep 13 14:28:37 EDT 2004


kdahlhaus at yahoo.com (Kevin Dahlhausen) writes:

> Could anyone post a simple setup.py script that uses a SWIG interface
> to C++ code  and the mingw compiler?
>
> I followed some online samples, and am using the setup.cfg file to
> specify swig-c++=1.
>
> Trying to build using mingw out of the cygwin environment but the
> final call to link the extension calls directly to 'cc' which I think
> should really be g++ at that point.
>
> Did get everything to build with a Makefile, but that's not the right
> way to go.

That's what I do: a Makefile that runs swig, and setup.py just
compiles the output.

One advantage with this approach is you can include the SWIG'd sources
in your distribution tarball, and your user then doesn't need to have
SWIG installed (assuming you don't use the SWIG runtime library, of
course). I also use pyrex in my project, and I do the same thing with it.

The other advantage is it's easy to pass the appropiate parameters to
swig (mine are -c++ -Wall -python -modern), without digging around
into internals.

If you look at the code in distutils for SWIG support, it's a hack:
pasted on for this one tool, and very annonying to extend. And using
it with C++ is even worse. On some machines, I use a different C++
compiler than the C compiler (GNU C++ with Compaq C, for instance),
and distutils makes a hash of that.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list