How do I pass structures using a C extension?

Jaime Wyant at
Tue Mar 15 17:55:14 CET 2005

I've never built a swig extension module using distutils.  Heck, i've
only rolled up pure python code using it... that's pretty slick..

Oh, anyway, make sure that libcmdline.h is in swigs search path. 
Either copy libcmdline.h to $CWD or figure out how to pass -I to swig
from distutils:

-I<dir>         - Look for SWIG files in <dir>

You may find it easier to roll the swig wrappers by hand... It's not
that hard really...


On 15 Mar 2005 06:50:52 -0800, timothy.williams at
<timothy.williams at> wrote:
> I have access to the source, so it seems that I can create shareable
> libs for the libraries I want to use using distutils. I do a
> glob.glob() on the *.c files in the libscr directory.  If I copy the
> main library.h file over to where my module.i file is, I can do a
> %include on it and things seem to get built fine. (I still need to
> actually call something to see if it works.)
> Is there a way to change my file to look in the locations
> specified by the 'include_dirs' argument? This argument works for my C
> compiling, but it doesn't get passed to swig.
> #!/bin/env python
> import sys, os, glob
> from distutils.core import setup, Extension
> py_version='python%d.%d' % (sys.version_info[0],sys.version_info[1])
> OTB_HOME='/vps/otbknox/williams/OTB_2.0'
>     os.path.join(OTB_HOME, 'include', 'global'),
>     os.path.join(OTB_HOME, 'include', 'libinc'),
>     os.path.join(sys.prefix,'include',py_version),
>     OTB_HOME
>     ]
> libsrcs=glob.glob(os.path.join(OTB_HOME,'libsrc','libcmdline','*.c'))
> setup (name = 'OTB_libs',
>        version='1.0',
>        author="Tim Williams",
> ##       packages=['cmdline'],
> ##       ext_package='OTB_libs',
>        ext_modules=[Extension('_cmdline',
>                               sources=['cmdline.i']+ libsrcs,
>                               include_dirs=OTB_INCLDIR
>                               )
>                     ]
>        )
> running build
> running build_ext
> building '_cmdline' extension
> swigging cmdline.i to cmdline_wrap.c
> swig -python -o cmdline_wrap.c cmdline.i
> cmdline.i:9: Unable to find 'libcmdline.h'
> error: command 'swig' failed with exit status 1
> --

More information about the Python-list mailing list