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

timothy.williams at nvl.army.mil timothy.williams at nvl.army.mil
Thu Mar 17 16:05:39 CET 2005


I installed Python 2.4. Now I can use swig_opts, but now I'm having a
problem with compiling my cmdline_wrap.c file

########## cmdline.i  #################
%module cmdline
%{
#include <libcmdline.h>
%}

%include <libcmdline.h>

########## setup.py ####################
#!/bin/env python
import sys, os
import pprint
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(sys.prefix,'include',py_version),
    os.path.join(OTB_HOME, 'include', 'global'),
    os.path.join(OTB_HOME, 'include', 'libinc'),
    OTB_HOME
    ]
OTB_LIBDIR=[os.path.join(OTB_HOME,'lib')]
swig_opts=['-includeall','-I/usr/include']
for d in OTB_INCLDIR:
    swig_opts.append('-I%s' % d)

##pprint.pprint(swig_opts)
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=swig_opts
                              )
                    ],
       py_modules=['OTB_libs.cmdline']
       )
###############

running build_ext
building '_cmdline' extension
swigging OTB_libs/cmdline.i to OTB_libs/cmdline_wrap.c
swig -python -includeall -I/usr/include
-I/project/c4i/Users_Share/williams/Linux/include/python2.4
-I/vps/otbknox/williams/OTB_2.0/include/global
-I/vps/otbknox/williams/OTB_2.0/include/libinc
-I/vps/otbknox/williams/OTB_2.0 -o OTB_libs/cmdline_wrap.c
OTB_libs/cmdline.i
OTB_libs/config.h:413: Warning(302): Identifier 'HAVE_UNISTD_H' redeclared
(ignored).
OTB_libs/config.h:15: Previous declaration of 'HAVE_UNISTD_H'
/usr/include/sys/cdefs.h:147: Warning(305): Bad constant value (ignored).
/usr/bin/gcc33 -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC
-I/project/c4i/Users_Share/williams/Linux/include/python2.4
-I/vps/otbknox/williams/OTB_2.0/include/global
-I/vps/otbknox/williams/OTB_2.0/include/libinc
-I/vps/otbknox/williams/OTB_2.0
-I/project/c4i/Users_Share/williams/Linux/include/python2.4 -c
OTB_libs/cmdline_wrap.c -o build/temp.linux-i686-2.4/OTB_libs/cmdline_wrap.o
OTB_libs/cmdline_wrap.c: In function `_wrap_mtx32vec64_vec_set':
OTB_libs/cmdline_wrap.c:742: error: structure has no member named `vec_size'
OTB_libs/cmdline_wrap.c:742: error: incompatible types in assignment
OTB_libs/cmdline_wrap.c: In function `_wrap_mtx32vec64_rot_set':
OTB_libs/cmdline_wrap.c:781: error: structure has no member named `rot_size'
OTB_libs/cmdline_wrap.c:781: error: incompatible types in assignment
OTB_libs/cmdline_wrap.c: In function `_wrap_gcs_rmatrix64_rot_set':
OTB_libs/cmdline_wrap.c:1150: error: structure has no member named
`rot_size'
OTB_libs/cmdline_wrap.c:1150: error: incompatible types in assignment
OTB_libs/cmdline_wrap.c: In function `_wrap_gcs_rmatrix32_rot_set':
OTB_libs/cmdline_wrap.c:1260: error: structure has no member named
`rot_size'
OTB_libs/cmdline_wrap.c:1260: error: incompatible types in assignment
OTB_libs/cmdline_wrap.c: At top level:
OTB_libs/cmdline_wrap.c:187: warning: `SWIG_Python_TypeDynamicCast' defined
but not used
OTB_libs/cmdline_wrap.c:199: warning: `SWIG_Python_TypeName' defined but not
used
OTB_libs/cmdline_wrap.c:205: warning: `SWIG_Python_TypeQuery' defined but
not used
OTB_libs/cmdline_wrap.c:444: warning: `SWIG_Python_addvarlink' defined but
notused
OTB_libs/cmdline_wrap.c:551: warning: `SWIG_Python_MustGetPtr' defined but
notused
OTB_libs/cmdline_wrap.c:559: warning: `SWIG_Python_ConvertPacked' defined
but not used
error: command '/usr/bin/gcc33' failed with exit status 1
##############

I think this is coming from the typedefs in stdtypes.h: (#include'd by
libcmdline.h)

/* The following are vector definitions */
typedef float32 vec3d32[3];
typedef float64 vec3d64[3];

typedef float32 vec2d32[2];
typedef float64 vec2d64[2];

typedef float32 rmatrix32[3][3];
typedef float64 rmatrix64[3][3];

typedef float32 rtmatrix32[4][3];
typedef float64 rtmatrix64[4][3];

typedef struct {
    vec3d64     vec;   /* Placed before single-precision to assure alignment
*/
    rmatrix32   rot;
} mtx32vec64;

I'm starting to think that this library I'm trying to write an extension for
has just too many nested typedefs for SWIG to handle. (And this is one of
the simpler libraries that don't have dependencies on other libraries!)

If I take out the -includeall switch, the _cmdline.so library builds, but
when I try to import the module I get:

Python 2.4 (#2, Feb 23 2005, 11:35:23)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import OTB_libs.cmdline
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File
"/project/c4i/Users_Share/williams/Linux/lib/python2.4/site-packages/OTB_lib
s/cmdline.py", line 5, in ?
    import _cmdline
ImportError:
/project/c4i/Users_Share/williams/Linux/lib/python2.4/site-packages/OTB_libs
/_cmdline.so: undefined symbol: cmd_aggregate

This is a function in the libcmdline.a (static, I know) that I'm trying to
use.



More information about the Distutils-SIG mailing list