segfault 使用 SWIG 为 tcl 转换的代码
我的程序出现分段错误.
I'm having a segmentation fault with my program.
事实上,我用 C++ 编写了一个库,并使用 SWIG 将其转换为 tcl.
In fact I write a library in C++ and convert it for tcl using SWIG.
段错误发生在这里:
return Tcl_NewIntObj(static_cast< int >(value));
其中值=0
gdb 回溯显示:
(gdb) bt
#0 0x000054b6 in ?? ()
#1 0xb6650d5d in SWIG_From_long (value=0) at mntdisplay_wrap.cc:1712
#2 SWIG_From_int (value=0) at mntdisplay_wrap.cc:1722
#3 Testguimnt_Init (interp=0x9714e28) at mntdisplay_wrap.cc:3774
#4 0xb76748fe in Tcl_LoadObjCmd () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#5 0xb75d02af in TclNREvalObjv () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#6 0xb75d0859 in Tcl_EvalObjv () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#7 0xb75d0d99 in TclEvalEx () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#8 0xb7670045 in Tcl_FSEvalFileEx () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#9 0xb767645f in Tcl_MainEx () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#10 0x0804885c in main ()
在包装器中:第 1712 行:
In the wrapper: line 1712:
SWIGINTERNINLINE Tcl_Obj*
SWIG_From_long (long value)
{
if (((long) INT_MIN <= value) && (value <= (long) INT_MAX)) {
return Tcl_NewIntObj(static_cast< int >(value)); //1712
} else {
return Tcl_NewLongObj(value);
}
}
1722:
SWIGINTERNINLINE Tcl_Obj *
SWIG_From_int (int value)
{
return SWIG_From_long (value); //1722
}
3774:
SWIG_Tcl_SetConstantObj(interp, "MESSAGE_NEW", SWIG_From_int(static_cast< int >(MESSAGE_NEW)));
其中 MESSAGE_NEW 在枚举中定义并且为 0.
where MESSAGE_NEW is defined in a enum and is 0.
如果您有任何想法,请帮助我.谢谢!
Please, if you have any idea, please help me. Thank you!
我找到了问题的原因:这是一个链接错误.
I found the cause of the problem: it's an linking error.
我为这个问题创建了一个新线程:
I created a new thread for this issue:
C++:链接库在执行期间消失并给出段错误
推荐答案
我发现了问题.
请看我的另一篇文章:C++:链接库在执行期间消失并给出段错误
我的库中有一个未定义的符号.我定义了它并解决了问题!
There was an undefined symbol of my library. I defined it and problem solved!
令人困惑的是,我的程序在 tcl 包装函数的中间崩溃了(我的未定义符号根本不涉及).我真的不知道为什么,但就是这样..
The confusion was, my program crashed in the middle of tcl wrapper functions (where my undefined symbol was not involved at all). I don't really know why but that's it..
希望它能帮助其他人!
相关文章