程序退出时出现段错误 (-11)
Segfault (-11) on program exit
我正在尝试让 goocanvasmm
从 C++ 程序中运行。来自一对
我组合代码片段并让程序绘制的地方。
但是,在程序终止时,会出现段错误。我不是普通 C++
用户,
因此,gdb
消息对我来说有些神秘。
这是代码。它创建一个 window,并在其中绘制一个 200x200 像素的黄色方块:
#include <gtkmm.h>
#include <goocanvasmm.h>
#include <iostream>
#define UI_FILE "gtk_foobar.ui"
int
main (int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
//Load the Glade file and instiate its widgets:
Glib::RefPtr<Gtk::Builder> builder;
try {
builder = Gtk::Builder::create_from_file(UI_FILE);
}
catch (const Glib::FileError & ex) {
std::cerr << ex.what() << std::endl;
return 1;
}
Gtk::Window *main_win = 0;
builder->get_widget("main_window", main_win);
Goocanvas::Canvas canvas;
main_win->add(canvas);
auto root = (canvas).get_root_item();
auto rect = Goocanvas::Rect::create(100, 100, 200, 200);
rect->property_stroke_color() = "yellow";
rect->property_line_width() = 3;
root->add_child(rect);
main_win->show_all();
if (main_win) {
kit.run(*main_win);
}
return 0;
}
运行-时间错误信息(在程序终止时显示):
Program has been terminated receiving signal 11 (Segmentation fault)
和 gdb
回溯:
#0 0x00007ffff5ae7d6c in free () at /lib64/libc.so.6
#1 0x00007ffff5a97736 in __cxa_finalize () at /lib64/libc.so.6
#2 0x00007ffff7d22946 in __do_global_dtors_aux () at /usr/lib64/libgoocanvasmm-2.0.so.6
#3 0x00007ffff7ffd060 in _rtld_local () at /lib64/ld-linux-x86-64.so.2
#4 0x0000000000000000 in ()
如果我没记错的话,这似乎表明其中的析构函数有问题
libgoocanvasmm
.
编辑: 我意识到(有点晚了),对于 运行 应用程序,还需要 UIFILE
。这是 ("gtk_foobar.ui"):
<?xml version="1.0"?>
<interface>
<!-- interface-naming-policy project-wide -->
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="main_window">
<property name="visible">True</property>
<property name="title" translatable="yes">Hello World!</property>
<property name="default_width">500</property>
<property name="default_height">400</property>
<child>
<placeholder/>
</child>
</object>
</interface>
为了方便起见,this link 将下载完整的 autotools
项目。
感谢@BobMorane 对程序进行了测试,发现库之间存在细微的版本差异。看来我的源码包和他的源码包都标为2.0.6,但内部有一个小区别,1.90.9和1.90.11,这很重要。
用1.90.11版本重新编译问题解决了!
查看更新日志没有发现令人震惊的差异,而是进行了一系列次要的兼容性更新。重新运行 valgrind确实显示此消息消失:
==30082== Invalid free() / delete / delete[] / realloc()
==30082== at 0x483B71B: operator delete(void*) (vg_replace_malloc.c:802)
==30082== by 0x6C25735: __cxa_finalize (in /lib64/libc-2.30.so)
==30082== by 0x48FB945: ??? (in /usr/lib64/libgoocanvasmm-2.0.so.6.0.0)
==30082== by 0x4914FC0: ??? (in /usr/lib64/libgoocanvasmm-2.0.so.6.0.0)
==30082== by 0x6C25016: __run_exit_handlers (in /lib64/libc-2.30.so)
==30082== by 0x6C251C9: exit (in /lib64/libc-2.30.so)
==30082== by 0x6C03E61: (below main) (in /lib64/libc-2.30.so)
==30082== Address 0x8 is not stack'd, malloc'd or (recently) free'd
我正在尝试让 goocanvasmm
从 C++ 程序中运行。来自一对
我组合代码片段并让程序绘制的地方。
但是,在程序终止时,会出现段错误。我不是普通 C++
用户,
因此,gdb
消息对我来说有些神秘。
这是代码。它创建一个 window,并在其中绘制一个 200x200 像素的黄色方块:
#include <gtkmm.h>
#include <goocanvasmm.h>
#include <iostream>
#define UI_FILE "gtk_foobar.ui"
int
main (int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
//Load the Glade file and instiate its widgets:
Glib::RefPtr<Gtk::Builder> builder;
try {
builder = Gtk::Builder::create_from_file(UI_FILE);
}
catch (const Glib::FileError & ex) {
std::cerr << ex.what() << std::endl;
return 1;
}
Gtk::Window *main_win = 0;
builder->get_widget("main_window", main_win);
Goocanvas::Canvas canvas;
main_win->add(canvas);
auto root = (canvas).get_root_item();
auto rect = Goocanvas::Rect::create(100, 100, 200, 200);
rect->property_stroke_color() = "yellow";
rect->property_line_width() = 3;
root->add_child(rect);
main_win->show_all();
if (main_win) {
kit.run(*main_win);
}
return 0;
}
运行-时间错误信息(在程序终止时显示):
Program has been terminated receiving signal 11 (Segmentation fault)
和 gdb
回溯:
#0 0x00007ffff5ae7d6c in free () at /lib64/libc.so.6
#1 0x00007ffff5a97736 in __cxa_finalize () at /lib64/libc.so.6
#2 0x00007ffff7d22946 in __do_global_dtors_aux () at /usr/lib64/libgoocanvasmm-2.0.so.6
#3 0x00007ffff7ffd060 in _rtld_local () at /lib64/ld-linux-x86-64.so.2
#4 0x0000000000000000 in ()
如果我没记错的话,这似乎表明其中的析构函数有问题
libgoocanvasmm
.
编辑: 我意识到(有点晚了),对于 运行 应用程序,还需要 UIFILE
。这是 ("gtk_foobar.ui"):
<?xml version="1.0"?>
<interface>
<!-- interface-naming-policy project-wide -->
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="main_window">
<property name="visible">True</property>
<property name="title" translatable="yes">Hello World!</property>
<property name="default_width">500</property>
<property name="default_height">400</property>
<child>
<placeholder/>
</child>
</object>
</interface>
为了方便起见,this link 将下载完整的 autotools
项目。
感谢@BobMorane 对程序进行了测试,发现库之间存在细微的版本差异。看来我的源码包和他的源码包都标为2.0.6,但内部有一个小区别,1.90.9和1.90.11,这很重要。
用1.90.11版本重新编译问题解决了!
查看更新日志没有发现令人震惊的差异,而是进行了一系列次要的兼容性更新。重新运行 valgrind确实显示此消息消失:
==30082== Invalid free() / delete / delete[] / realloc()
==30082== at 0x483B71B: operator delete(void*) (vg_replace_malloc.c:802)
==30082== by 0x6C25735: __cxa_finalize (in /lib64/libc-2.30.so)
==30082== by 0x48FB945: ??? (in /usr/lib64/libgoocanvasmm-2.0.so.6.0.0)
==30082== by 0x4914FC0: ??? (in /usr/lib64/libgoocanvasmm-2.0.so.6.0.0)
==30082== by 0x6C25016: __run_exit_handlers (in /lib64/libc-2.30.so)
==30082== by 0x6C251C9: exit (in /lib64/libc-2.30.so)
==30082== by 0x6C03E61: (below main) (in /lib64/libc-2.30.so)
==30082== Address 0x8 is not stack'd, malloc'd or (recently) free'd