SWIG+Distutils - no harmony?

Martin Bless m.bless at gmx.de
Tue Jan 15 15:26:05 EST 2002

Getting courageous I try building 'example.pyd' 
from the SWIG 'Simple Example' using SWIG and the Distutils.
Looks promising but doesn't succeed. I didn't
modify 'example.c' and 'example.i'.


(1) Is 'setup.py' ok?
(2) BEWARE: What's really shocking:
After see (unsuccessful)
  python setup.py build -cmingw32
the original 'example.c' is GONE AND AWAY -
replaced by the wrapper.
(3) What's going wrong?


Sources und logs following:

# setup.py
# mb: Is this ok?
import distutils
from distutils.core import setup, Extension
#from distutils.extension import Extension

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

/* File : example.i */
%module example

extern int    gcd(int x, int y);
extern double Foo;
/* File : example.c */

/* A global variable */
double Foo = 3.0;

/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
  int g;
  g = y;
  while (x > 0) {
    g = x;
    x = y % x;
    y = g;
  return g;

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

swig -version

SWIG Version 1.3.10u-20011211-2004
Copyright (c) 1995-1998
University of Utah and the Regents of the University of California
Copyright (c) 1998-2001
University of Chicago

Compiled with CC

>python setup.py build -cmingw32

running build
running build_ext
building 'example' extension
swigging example.i to example.c
c:\pyext\swig\swig.exe -python -dnone 
  -ISWIG -o example.c example.i
c:\mingw\bin\gcc.exe -mno-cygwin -mdll 
  -O -Wall -IC:\PYTHON22\include 
  -c example.c -o build\temp.win32-2.2\Release\example.o
writing build\temp.win32-2.2\Release\example.def

c:\mingw\bin\gcc.exe -mno-cygwin -mdll -static 
  -s build\temp.win32-2.2\Release\example.o 
  -LC:\PYTHON22\libs -lpython22 
  -o build\lib.win32-2.2\example.pyd

swig: Warning. -dnone option deprecated.

example.c: In function `SWIG_UnpackData':
example.c:363: warning: `uu' might be used uninitialized in this
example.c: In function `SWIG_ConvertPtr':
example.c:429: warning: suggest explicit braces to avoid ambiguous
example.c:432: warning: suggest explicit braces to avoid ambiguous
example.c:438: warning: suggest explicit braces to avoid ambiguous
example.c: At top level:
example.c:154: warning: `SWIG_TypeQuery' defined but not used
example.c:385: warning: `SWIG_ConvertPtr' defined but not used
example.c:468: warning: `SWIG_ConvertPacked' defined but not used
example.c:537: warning: `SWIG_MakeShadow' defined but not used
undefined reference to `gcd'
undefined reference to `Foo'
undefined reference to `Foo'
undefined reference to `Foo'
error: command 'gcc' failed with exit status 1


More information about the Python-list mailing list