SWIG&C/C++Python API已连接-SEGFAULT
我的任务是创建双程序。开始时,我启动了一个C程序,通过Python的C/C++API调用一些Python方法。调用之后调用的方法是使用SWIG创建的函数。我给你们看我的样本,在我被给出分段错误后,我还从gdb返回跟踪 主要条款c: 最后一个想法是我的Makefile&SWIG配置文件 生成文件: rm-rf*.o 程序由./main调用,并有以下输出: 回溯: gdb回溯SWIG&C/C++Python API已连接-SEGFAULT,python,c,swig,Python,C,Swig,我的任务是创建双程序。开始时,我启动了一个C程序,通过Python的C/C++API调用一些Python方法。调用之后调用的方法是使用SWIG创建的函数。我给你们看我的样本,在我被给出分段错误后,我还从gdb返回跟踪 主要条款c: 最后一个想法是我的Makefile&SWIG配置文件 生成文件: rm-rf*.o 程序由./main调用,并有以下输出: 回溯: gdb回溯 #0 0xb7ed3e4e in PyObject_Malloc () from /usr/lib/libpython2.
#0 0xb7ed3e4e in PyObject_Malloc () from /usr/lib/libpython2.6.so.1.0
#1 0xb7ca2b2c in ?? ()
#2 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#3 0xb7eb014c in ?? () from /usr/lib/libpython2.6.so.1.0
#4 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#5 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0
#6 0x00000001 in ?? ()
#7 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#8 0xb7f4f014 in _PyObject_GC_Malloc () from /usr/lib/libpython2.6.so.1.0
#9 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0
#10 0xb7f4f104 in _PyObject_GC_NewVar () from /usr/lib/libpython2.6.so.1.0
#11 0xb7ee8760 in _PyType_Lookup () from /usr/lib/libpython2.6.so.1.0
#12 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0
#13 0x00000001 in ?? ()
#14 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#15 0xb7ef13ed in ?? () from /usr/lib/libpython2.6.so.1.0
#16 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#17 0x00000001 in ?? ()
#18 0xbfff0c34 in ?? ()
#19 0xb7e993c3 in ?? () from /usr/lib/libpython2.6.so.1.0
#20 0x00000001 in ?? ()
#21 0xbfff0c70 in ?? ()
#22 0xb7f99da0 in ?? () from /usr/lib/libpython2.6.so.1.0
#23 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#24 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#25 0x080a6b0c in ?? ()
#26 0x080a6b0c in ?? ()
#27 0xb7e99420 in PyObject_CallFunctionObjArgs () from /usr/lib/libpython2.6.so.1.0
#28 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#29 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#30 0x800e55eb in ?? ()
#31 0x080a6b0c in ?? ()
#32 0xb7e9958c in PyObject_IsSubclass () from /usr/lib/libpython2.6.so.1.0
#33 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#34 0x080a9020 in ?? ()
#35 0xb7fb78f0 in PyFPE_counter () from /usr/lib/libpython2.6.so.1.0
#36 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#37 0x00000000 in ?? ()
感谢您的帮助和建议,marxin计数器究竟是在哪里定义的?计数器是在utils.h中定义的静态变量。但我认为删除变量与我的问题无关。计数器到底是在哪里定义的?计数器是在utils.h中定义的静态变量。但我认为删除变量与我的问题无关。
#include <stdio.h>
#include "utils.h"
void increment(void)
{
printf("Incremention counter to: %u\n", ++counter);
}
#!/usr/bin/python2.6
'''py_function.py - Python source designed to demonstrate the use of python embedding'''
import utils
def ink():
print 'I am gonna increment !'
utils.increment()
CC=gcc
CFLAGS=-c -g -Wall -std=c99
all: main
main: main.o utils.o utils_wrap.o
$(CC) main.o utils.o -lpython2.6 -o sample
swig -Wall -python -o utils_wrap.c utils.i
$(CC) utils.o utils_wrap.o -shared -o _utils.so
main.o: main.c
$(CC) $(CFLAGS) main.c -I/usr/include/python2.6 -o main.o
utils.o: utils.c utils.h
$(CC) $(CFLAGS) -fPIC utils.c -o $@
utils_wrap.o: utils_wrap.c
$(CC) -c -fPIC utils_wrap.c -I/usr/include/python2.6 -o $@
clean:
(gdb) run
Starting program: /home/marxin/Programming/python2/sample
[Thread debugging using libthread_db enabled]
Calling from C !
Incremention counter to: 1
I am gonna increment !
Incremention counter to: 2
before finalize
after finalize
I am gonna increment !
Incremention counter to: 3
before finalize
after finalize
I am gonna increment !
Incremention counter to: 4
before finalize
after finalize
Program received signal SIGSEGV, Segmentation fault.
0xb7ed3e4e in PyObject_Malloc () from /usr/lib/libpython2.6.so.1.0
#0 0xb7ed3e4e in PyObject_Malloc () from /usr/lib/libpython2.6.so.1.0
#1 0xb7ca2b2c in ?? ()
#2 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#3 0xb7eb014c in ?? () from /usr/lib/libpython2.6.so.1.0
#4 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#5 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0
#6 0x00000001 in ?? ()
#7 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#8 0xb7f4f014 in _PyObject_GC_Malloc () from /usr/lib/libpython2.6.so.1.0
#9 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0
#10 0xb7f4f104 in _PyObject_GC_NewVar () from /usr/lib/libpython2.6.so.1.0
#11 0xb7ee8760 in _PyType_Lookup () from /usr/lib/libpython2.6.so.1.0
#12 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0
#13 0x00000001 in ?? ()
#14 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#15 0xb7ef13ed in ?? () from /usr/lib/libpython2.6.so.1.0
#16 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#17 0x00000001 in ?? ()
#18 0xbfff0c34 in ?? ()
#19 0xb7e993c3 in ?? () from /usr/lib/libpython2.6.so.1.0
#20 0x00000001 in ?? ()
#21 0xbfff0c70 in ?? ()
#22 0xb7f99da0 in ?? () from /usr/lib/libpython2.6.so.1.0
#23 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#24 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#25 0x080a6b0c in ?? ()
#26 0x080a6b0c in ?? ()
#27 0xb7e99420 in PyObject_CallFunctionObjArgs () from /usr/lib/libpython2.6.so.1.0
#28 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#29 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#30 0x800e55eb in ?? ()
#31 0x080a6b0c in ?? ()
#32 0xb7e9958c in PyObject_IsSubclass () from /usr/lib/libpython2.6.so.1.0
#33 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0
#34 0x080a9020 in ?? ()
#35 0xb7fb78f0 in PyFPE_counter () from /usr/lib/libpython2.6.so.1.0
#36 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#37 0x00000000 in ?? ()