467,222 Members | 1,447 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,222 developers. It's quick & easy.

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

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.
Jul 18 '05 #1
  • viewed: 2533
Share:
3 Replies
kd*******@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
Jul 18 '05 #2
kd*******@yahoo.com (Kevin Dahlhausen) wrote in message news:<28**************************@posting.google. com>...
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.

Maybe my pyMinGW can help you. Though still not 100% done, pyMinGW
includes a patch to distutils so as (among other things) to fix that
which you ask about.

Read about pyMinGW here:
http://jove.prohosting.com/iwave/ipython/pyMinGW.html

There is also a CPP-Swig example found in the Mingw\extensions
directory of both py24a3MinGW-004a.zip, and py234MinGW-015.zip.

Before you do anything, please backup the following files:

[1] Lib/distutils/ccompiler.py
[2] Lib/distutils/cygwinccompiler.py
[3] Lib/distutils/unixccompiler.py
[4] Lib/distutils/command/build_ext.py
in case you don't like the patch, and would like to restore your
distutils to its original state. Once you've done that then you can
replace those four files with the ones in the patch. Hopefully that'll
do it for you.

--
Q. The purpose of life?

[A]: "I created the jinn and humankind only that they might
worship Me." (Translation, Qur'an, 51:56)

[b]: "Let us hear the conclusion of the whole matter:
Fear God, and keep his commandments: for this is the
whole duty of man." (KJV, Ecclesiastes 12:13)
Jul 18 '05 #3
Thanks for the responses. Not forcing a depdency on swig makes sense
to me, so I'm going with that for the moment. I will take a look at
pyMinGW too.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Derek Croxton | last post: by
reply views Thread by Holger Joukl | last post: by
2 posts views Thread by Helmut Jarausch | last post: by
reply views Thread by ReaprZero | last post: by
reply views Thread by John Ling | last post: by
1 post views Thread by Stou Sandalski | last post: by
1 post views Thread by =?GB2312?B?zPC5zw==?= | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.