SWIG+Distutils - no harmony?

Martin Bless m.bless at gmx.de
Wed Jan 16 17:25:11 EST 2002


["Thomas Heller" <thomas.heller at ion-tof.com>]:
>A distutils bug. Support for SWIG is rather poor.
>SWIGging a file <pathname>.i creates a file <pathname>.c
>overwriting any previous file of this name. So better
>change another name.

It's working now. Here's what I changed to get things going:

>----------<>----------<>----------<
I changed two lines in distutils.command.build_ext.py

(1) in function 
    def swig_sources (self, sources):
    [...]
        #new_sources.append(base + target_ext)      #old
        new_sources.append(base + '_wrap' + target_ext)  #new

This prevents the C-source from getting overwritten.
Adding '_wrap' to the base is the naming convention SWIG  1.3 employs
anyway if not told otherwise.

(2) I use a different SWIG commandline. Second change:

        #swig_cmd = [swig, "-python", "-dnone", "-ISWIG"] #old
        swig_cmd = [swig, "-python"]  #new

>----------<>----------<>----------<
# 3.  change: added "example.c"  to extension list
#
# setup.py
import distutils
from distutils.core import setup, Extension

setup(name = "Example 'Simple' from the SWIG examples",
      version = "2.2",
      ext_modules = [Extension("example", ["example.i","example.c"])])

>----------<>----------<>----------<

Thankful,

Martin

PS: ... and yes, the docs are poor or outdated. The SWIG doc about
Python is from 1997 and deals with Python 1.3 and 1.4. Feels like an
ancient millenium ;-)



More information about the Python-list mailing list