SWIG Python undefined reference

Paul Melis paul at science.uva.nl
Tue Apr 29 07:18:32 EDT 2008


Instead of manually trying to get all the options to gcc correct you 
might want to look at using distutils for compiling your extension.
See the SWIG documentation, section 30.2.2 
(http://www.swig.org/Doc1.3/Python.html#Python_nn6)

Paul

Soren wrote:
> Hi,
> 
> I went through the SWIG tutorial for the example named "simple".
> 
> I managed to get to the first step, creating example_wrap.c using
> swig, and doing:
> "gcc -fpic -c example_wrap.c -IC:\python24\include " to create
> example_wrap.o
> 
> But when I needed to compile the library file using:
> "gcc -shared example_wrap.o -o examplemodule.so" I received a lot of
> undefined reference compiler errors like:
> 
> example_wrap.o(.text+0x35a5):example_wrap.c: undefined reference to
> `_imp__PyErr
> _SetString'
> 
> there are many other similar errors all prefaced with _imp__Py, so I
> am assuming there is a linker error with the python libraries. I have
> adjusted my PATH variable to include all the python directories (libs/
> dlls).
> 
> Does anyone here have any suggestions?
> 
> FILES FROM TUTORIAL:
> 
> 
> //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;
> time(&ltime);
> return ctime(&ltime);
> }
> //***************************************************************
> 
> //example.i
> %module example
> %{
> /* Put header files here or function declarations like below */
> extern double My_variable;
> extern int fact(int n);
> extern int my_mod(int x, int y);
> extern char *get_time();
> %}
> 
> extern double My_variable;
> extern int fact(int n);
> extern int my_mod(int x, int y);
> extern char *get_time();
> //***************************************************************
> 
> //setup.py
> from distutils.core import setup, Extension
> 
> setup(name='example',
> version = '1.0',
> ext_modules=[
> Extension('example', ['example.c', 'example.i'])
> ])



More information about the Python-list mailing list