1
我的程序出現了段錯誤。segfault使用SWIG轉換代碼爲tcl
事實上,我用C++編寫一個庫,並使用SWIG將其轉換爲tcl。
的段錯誤發生位置:
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:
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
請,如果您有任何想法,請幫助我。謝謝!
編輯:
我找到了問題的原因:這是一個鏈接錯誤。
我創建了一個新的線程針對此問題:
C++: linked library disappears and gives segfault during execution