[python-win32] Linking Python Libraries With GCC In WIndows XP Using SWIG

Steve Farris sfarris at ll.mit.edu
Tue Sep 23 09:49:32 EDT 2003


I have generated a very basic SWIG example from a SWIG tutorial at 
http://www.swig.org <http://www.swig.org/>.  This example compiles and 
interfaces correctly with Python2.2.3 in RedHat Linux9.0.  When I 
attempt to compile and link this example with the gnu compiler in 
Windows XP I am getting link errors indicating the python libraries are 
not included even though I have included the Python include headers in 
the compile-stage, and the Python library python22.LIB in the link stage.

 

For completeness I have included the SWIG example.c and example.i files 
created below along with the Link errors I am seeing. Any suggestions as 
to why the linker is not seeing the Python modules indicated in the 
errors below?  I am using prepackaged executables and libraries for 
Python2.2.3, gcc, and SWIG1.3.13 (note:  I tried this with SWIG1.3.19 
with the same results).

Thanks-

Steve Farris
 

Note: The example below is taken directly from a SWIG Tutorial at the

      http://www.swig.org <http://www.swig.orm/> web site.

/* File : example.c From a SWIG Tutorial*/

/* 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;

}

 

/* File : example.i */

%module example

 

extern int    gcd(int x, int y);

extern double Foo;

 

The process I am following for compiling and linking are as follows;

 

swig -python example.i

gcc -c -I<PythonPath>\include example.c example_wrap.c

gcc -shared -L<PythonPath>\libs\python22.LIB example.o example_wrap.o -o 
examplemodule.so

 

The first two steps run correctly.  The third step (linking) gives me 
the following first few errors (there are several more, all similar to 
these;

 

example_wrap.o(.text+0x338):example_wrap.c: undefined reference to 
'_imp__PyString_FromString'

 

example_wrap.o(.text+0x44d):example_wrap.c: undefined reference to 
'_imp__PyExc_NameError'

 

example_wrap.o(.text+0x454):example_wrap.c: undefined reference to 
'_imp__PyErr_SetString'

 

example_wrap.o(.text+0x4c1):example_wrap.c: undefined reference to 
'_imp__PyExc_NameError'

 

example_wrap.o(.text+0x4c8):example_wrap.c: undefined reference to 
'_imp__PyErr_SetString'

 

example_wrap.o(.text+0x507):example_wrap.c: undefined reference to 
'_imp__PyType_Type'

 

etc...

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20030923/dbc39af7/attachment.html


More information about the Python-win32 mailing list