SWIG: ImportError: dynamic module does not define init function

Louis Luangkesorn lluang at northwestern.edu
Mon Sep 17 05:23:34 CEST 2001

I'm trying to run the example from the SWIG User's Guide (V 1.1 June 23,
1997)  When I try to load the example I get the following:

PythonWin 2.1 (#15, Apr 19 2001, 10:28:27) [MSC 32 bit (Intel)] on
Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) - see
'Help/About PythonWin' for further copyright information.
>>> import sys
>>> sys.path.append('c:\lluang\gmcode\cnumint\debug')
>>> import cnumint
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
ImportError: dynamic module does not define init function (initcnumint)

I've noticed on various mailing lists several people have asked this
same question, but I have not seen anyone respond to this.  Is there
something I'm missing?  Thanks.

Oh, when I compile, I get a "Bad command or file name" error, but the
dll continues to compile with a 0 errors, 0 warnings message.  Thanks
for your help.


SWIG Version 1.3.6u-2001
MSVC++ 6
Settings: (teken from Ch 9: SWIG and Python Pg. 163
Custom Build -> Commands
swig -python -o $(ProjDir)\$(InputName)_wrap.c $(InputPath)
Custom Build -> Outputs

Project settings
C++ Preprocessor->Additional include directories
c:/python20/include  (note, I have Python 2.1 installed in my python20

Link -> Output file name

Link library

int fact(int n);
int my_mod(int n, int m);
double My_variable = 3.0;

/* compute factorial of n */

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

/* Compute n mod m */
int my_mod(int n, int m) {
 return (n % m);

int main() {
 return 0;

%module cnumint
extern double My_variable;
extern int fact(int n);
extern int my_mod(int n, int m);

K Louis Luangkesorn
lluang at northwestern.edu  http://pubweb.nwu.edu/~kll560  PGP:0xF3E2D362
Whatsoever things are true, ... honest, ... just, ... pure, ... lovely,
... of good report; if there be any virtue, and if there be any praise,
think on these things.- motto - Northwestern University

More information about the Python-list mailing list