building modules with swig- mingGW compiler

Craig Howard craighoward at
Sun Jan 5 21:27:21 CET 2003


I'm using python 2.2.2, swig 1.3.17, and minGW in order to build a simple
python module, and am running into an error.

I've created the libpython22.a, and added the following changes to

    #new_sources.append(base + target_ext) # old
     new_sources.append(base + '_wrap' + target_ext) # new

     #swig_cmd = [swig, "-python", "-dnone", "-ISWIG"] # old
     swig_cmd = [swig, "-python"] # new

I've created a file example.c:

/* File : example.c */
 #include <time.h>
 double My_variable = 3.0;

 int fact(int n) {
     if (n <= 1) return 1;
     else return n*fact(n-1);

 int my_mod(int x, int y) {
     return (x%y);

 char *get_time() {
     time_t ltime;
     return ctime(&ltime);

I've created a file example.i

/* example.i */
 %module example
 /* Put header files here (optional) */

 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();

I've created a file

 import distutils
 from distutils.core import setup, Extension

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

Then I run the command: python build -cmingw32
and I get an error:
example.exp(.edata+0x34):fake: undefined reference to 'initexample'
dllwrap: gcc exited with status 1
error: command 'dllwrap' failed with exit status 1

More information about the Python-list mailing list