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

K

Kevin Dahlhausen

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.
 
D

David M. Cooke

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.
 
A

A. B., Khalid

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)

: "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)
 
K

Kevin Dahlhausen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top