[Distutils] C++, swig, and distutils
Vishnu Bob
vishnubob at gmail.com
Fri Nov 18 23:27:24 CET 2005
Hi,
I have a two comments about the usability of C++, swig, and distutils.
I'm using python 2.4.2.
Comment 1:
First, build_ext.py:525 tests the list "swig_opts". If the string
"-c++" is in the swig_opts list, build_ext.py will build the wrapper
with a ".cpp" extension instead of the default ".c"
if self.swig_cpp or ('-c++' in self.swig_opts):
target_ext = '.cpp'
else:
target_ext = '.c'
However, "swig_cpp" is a command level option, and it's impossible to
set via the Extension() arguments. This gets a little weird, because of
build_ext.py:550:
# Do not override commandline arguments
if not self.swig_opts:
for o in extension.swig_opts:
swig_cmd.append(o)
This is below the "-c++" string test described above. So, if you
specify "-c++" like this:
Extension( 'package.module', ['src/module.i'],
swig_opts=['-c++'], language='c++' )
build_ext.py will include "-c++" into the swig command, but the output
file will /still/ have a ".c" extension. In order to workaround this
without specifying a command line argument or building a setup.cfg file,
you have to specify an "options" keyword argument in the call to setup():
options={'build_ext':{'swig_opts':'-c++'}}
Comment 2:
In spite of workaround described above, build_ext.py:464 compiles the
swig generated ".cpp" wrapper with "gcc". Luckily, gcc sees the ".cpp"
extension and switches to g++, but that's totally sloppy.
I've tried to coax distutils to use its C++ swig strategies with three
different variables, and it's still assuming C.
thanks,
-g
More information about the Distutils-SIG
mailing list