2009-11-26 51 views
1

使用SWIG链接到gtkglext的任何内容都会在退出时崩溃Python。为什么这会崩溃?为什么SWIG在链接到gtkglext时崩溃Python?

test.i:

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

会议:

$ 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 

任何想法?谢谢...

+0

当你在gdb下运行它会发生什么?跟踪使用'python -v'怎么样?核心转储是否在不调用test.test()的情况下发生?另外,尝试使用setup.py文件来构建扩展,所以Python本身管理编译器标志以及所需的库和库顺序。 – 2009-11-26 07:29:10

回答

1

你需要正确地初始化gtk。

$ 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. 
+0

这确实似乎解决了它,但你能解释为什么吗?我没有调用任何GTK函数,这对我来说没有意义。 – Steve 2009-11-27 02:31:26

+0

'import gtk'调用一些init函数。 – abbot 2009-11-27 05:29:01

+0

显然,但为什么我需要调用任何GTK初始化函数,如果我不是_using_ GTK,只能链接到它?当库简单链接时是否会自动调用某些代码? – Steve 2009-11-27 18:42:22