How do I pass structures using a C extension?

Jaime Wyant programmer.py at gmail.com
Tue Mar 15 11:55:14 EST 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...

hth,
jw

On 15 Mar 2005 06:50:52 -0800, timothy.williams at nvl.army.mil
<timothy.williams at nvl.army.mil> 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 setup.py 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'
> OTB_INCLDIR=[
>     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
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list