SWIG Python undefined reference

S

Soren

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'])
])
 
S

Soren

Ok I found out how to do it using:

gcc -Ic:\python24\include -Lc:\python24\libs --shared example_wrap.c
example.c -lpython24 -o _example.pyd

but now I get a "dynamic module does not define init function" error
when I try to import it into python..

Anyone??

Soren
 
S

Soren

Ok I found out how to do it using:

gcc -Ic:\python24\include -Lc:\python24\libs --shared example_wrap.c
example.c -lpython24 -o _example.pyd

but now I get a "dynamic module does not define init function" error
when I try to import it into python..

Anyone??

Soren

In case anyone is having the same problem the solution for me was:

gcc example.c example_wrap.c -Ic:\python24\include -Lc:\python24\libs -
lpython24 -Xlinker -expoert-dynamic -shared -o _example.pyd

Soren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top