views:

38

answers:

1

Anything I link to gtkglext using SWIG crashes Python on exit. Why does this crash?

test.i:

%module test
%{
void test() { printf("Test.\n"); }
%}
void test();

Session:

$ swig -python test.i

$ g++ -I/usr/include/python2.6 -shared -fPIC -o _test.so test_wrap.c -lpython2.6

$ python -c 'import test; test.test()'
Test.

$ g++ -I/usr/include/python2.6 -shared -fPIC -o _test.so test_wrap.c -lpython2.6 `pkg-config --libs gtkglext-1.0`

$ python -c 'import test; test.test()'
Test.
Segmentation fault

Any ideas? Thanks...

+1  A: 

You need to init gtk properly.

$ cat test.i 
%module test
%{
void test() { printf("Test.\n"); }
%}
void test();
$ swig -python test.i ; gcc -I/usr/include/python2.5 -shared -fPIC -o _test.so test_wrap.c -lpython2.5 `pkg-config --libs gtkglext-1.0`
$ python -c 'import test; test.test()'
Test.
Segmentation fault
$ python -c 'import gtk; import test; test.test()'
Test.
abbot
That does indeed seem to fix it but can you explain why? I'm not calling any GTK functions, this makes no sense to me.
Steve
`import gtk` calls some init functions.
abbot
Clearly, but why would I need to call any GTK init functions if I'm not _using_ GTK, only linking to it? Does some code get called automatically when a library is simply linked?
Steve