[Distutils] Distutils, SWIG, and C++
Ben Wagner
bungeman at lycos.com
Mon May 16 16:54:30 CEST 2005
I just downloaded the latest Distutils and am running Python24 on WindowsXP Pro and using MSVC Pro 2003. I'm developing a Python extention (.pyd) and want to use Distutils to manage the install process. After reading much documentation and code I have gotten everything to build and run manually, but am having difficulty with the setup configuration. What it boils down to is I have a Swig (.i) which is written in C++, mostly since it includes PythonCOM.h. Here is a slightly simplified version of my setup.py
<code>
#docs left out
from distutils.core import setup, Extension
import os
#using these two lines on my machine works to compile properly
#"C:\Program Files\SWIG-1.3.24\swig.exe" -python -c++ -o mouse_wrap.cpp mouse_client.i
#"C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe" /c /nologo /Ox /MD /W3 /GX /DNDEBUG -IC:\Python24\include -IC:\Python24\PC -IC:\Python24\Lib\site-packages\win32\include -IC:\Python24\Lib\site-packages\win32com\include /Tpmouse_wrap.cpp /Fobuild\mouse_wrap.obj
from distutils.sysconfig import get_python_lib
win32Incdir = os.path.join(get_python_lib(plat_specific=1), 'win32\include')
win32comIncdir = os.path.join(get_python_lib(plat_specific=1), 'win32com\include')
pythoncomLib = os.path.join(get_python_lib(plat_specific=1), 'win32com\libs\pythoncom')
wintypesLib = os.path.join(get_python_lib(plat_specific=1), 'win32\libs\pywintypes')
libs = ['user32', 'ole32', pythoncomLib, wintypesLib]
includes = [win32Incdir, win32comIncdir]
macros = [('NDEBUG', '1')]
compilerArgs = []
lang = 'c++'
swigOpts = ['-c++']
setup(name='pyCOMHook',
#standard setup stuff left out
ext_modules = [Extension('pyCOMHook._mouse', ['mouse.i'],
libraries=libs, include_dirs=includes, define_macros=macros,
extra_compile_args=compilerArgs, language=lang, swig_opts=swigOpts)],
)
</code>
This succesfuly puts '-c++' on the swig command line, but the output file (for Swig) is still .c (and not .cpp). After looking through the Distutils code I realized two things
1. build_ext.py [line 525, in swig_sources (self, sources, extension)] I think needs to be changed from
if self.swig_cpp or ('-c++' in self.swig_opts):
to
if self.swig_cpp or ('-c++' in self.swig_opts) or ('-c++' in extension.swig_opts):
or something like that. Doing this fixed my whole problem and everything ran fine.
2. even without the above fix, this still should have worked, even with the .c extention, but the msvccompiler.py compiler currently ignores the language setting and only uses file extentions to determine /Tc or /Tp flags
So my question is this, is it currently impossible to Swig a .i written in c++ on Windows using msvc and a bug fix is needed, or is there some nifty way around this which I have not yet been clever enough to ferret out? I would appreciate if anyone more familiar with the Distutils code could take a look into this.
--
_______________________________________________
NEW! Lycos Dating Search. The only place to search multiple dating sites at once.
http://datingsearch.lycos.com
More information about the Distutils-SIG
mailing list