[Distutils] How do I modify the swig options in my setup.py

timothy.williams at nvl.army.mil timothy.williams at nvl.army.mil
Wed Mar 16 21:20:37 CET 2005


I tried using swig_opts, but it didn't recognize it. I'm using python 2.3.2,
SWIG 1.3.21 if that matters.

#!/bin/env python
import sys, os
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
    ]
OTB_LIBDIR=[os.path.join(OTB_HOME,'lib')]

setup (name = 'OTB_libs',
       version='1.0',
       author="Tim Williams",
       packages=['OTB_libs'],
       ext_package='OTB_libs',
       ext_modules=[Extension('_cmdline',
                              sources=['OTB_libs/cmdline.i'],
                              include_dirs=OTB_INCLDIR,
                              library_dirs=OTB_LIBDIR,
                              libraries=['cmdline'],
                              swig_opts=['-includeall']
                              )
                    ],
       py_modules=['OTB_libs.cmdline']
       )
######################

/project/c4i/Users_Share/williams/Linux/lib/python2.3/distutils/extension.py
:128: UserWarning: Unknown Extension options: 'swig_opts'
  warnings.warn(msg)
running build
running build_py
copying OTB_libs/__init__.py -> build/lib.linux-i686-2.3/OTB_libs
copying OTB_libs/cmdline.py -> build/lib.linux-i686-2.3/OTB_libs
copying OTB_libs/cmdline.py -> build/lib.linux-i686-2.3/OTB_libs
copying OTB_libs/__init__.py -> build/lib.linux-i686-2.3/OTB_libs
running build_ext
building '_cmdline' extension
swigging OTB_libs/cmdline.i to OTB_libs/cmdline_wrap.c
swig -python -o OTB_libs/cmdline_wrap.c OTB_libs/cmdline.i
/usr/bin/g++33 -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/vps/otbknox/williams/OTB_2.0/include/global
-I/vps/otbknox/williams/OTB_2.0/include/libinc
-I/project/c4i/Users_Share/williams/Linux/include/python2.3
-I/vps/otbknox/williams/OTB_2.0
-I/project/c4i/Users_Share/williams/Linux/include/python2.3 -c
OTB_libs/cmdline_wrap.c -o build/temp.linux-i686-2.3/OTB_libs/cmdline_wrap.o
gcc -pthread -shared build/temp.linux-i686-2.3/OTB_libs/cmdline_wrap.o
-L/vps/otbknox/williams/OTB_2.0/lib -lcmdline -o
build/lib.linux-i686-2.3/OTB_libs/_cmdline.so

###################

I read over the typemaps some, but the libraries I'm trying to use have gobs
of typedefs in them, and I was hoping that the #include files for the
library would take care of it. (Beside me just not understanding enough
about typemaps to be comfortable using them.)



-----Original Message-----
From: Lars Immisch [mailto:lars at ibp.de]
Sent: Wednesday, March 16, 2005 2:46 PM
To: Williams, Timothy J Mr RDECOM CERDEC NVESD
Cc: 'distutils-sig at python.org'
Subject: Re: [Distutils] How do I modify the swig options in my setup.py



> I'm trying to use SWIG to create an extension to access some third party
> libraries I want to be able to change the options to include possible
> '-includeall', '-c++'.  I'm using distutils,  but I don't know how to
change
> from the default options.

 From inside setup.py, use swig_opts. See the following example:

import sys
from distutils.core import setup,Extension

setup (name = "sai",
        version = "2.0",
        description = "SAI Python wrapper",
        author = "Lars Immisch",
        author_email = "lars at ibp.de",
        ext_modules = [Extension("_sai", ["sai.i",
                                          "errorobject.c",
                                          "symname.c"],
                                 swig_opts = [ "-modern", "-new_repr",
                                               "-I..", "-I../../include"],
                                 include_dirs=["..", "../../include"],
                                 library_dirs=["."],
                                 libraries=["nsl", "pthread",
                                            "cSARU-genappl-api", "saru"])],
        py_modules = ['sai']
        )


> Also, a SWIG question: i build my _module.so and module_wrap.o, but when I
> try to call one of the functions, I get and error saying that the last
> argument was expected to be a pointer, but it isn't. I tried calling a
> couple of functions and both times SWIG is expecting the last arg to be a
> pointer. Any ideas?

Wrong typemaps ;-)

This sort of question is best asked with a minimal example on the swig 
mailing list, but do have a look into typemaps in the documentation.

A lot of useful typemaps are in python/typemaps.i.

- Lars


More information about the Distutils-SIG mailing list