Gtkmm 程序编译正常但崩溃 - windows XP
Posted
技术标签:
【中文标题】Gtkmm 程序编译正常但崩溃 - windows XP【英文标题】:Gtkmm program compiles fine but crashes - windows XP 【发布时间】:2014-05-31 13:28:11 【问题描述】:我最近安装了 gtkmm (gtkmm-2.4)
当我使用 g++ 编译时,我使用 pkg-config 中的以下信息
头文件
pkg-config gtkmm-2.4 --cflags
对象文件
pkg-config gtkmm-2.4 --libs
所以我编译了一个简单的 helloworld 问题,即在屏幕上显示一个窗口...
g++ gtkmm_app2.cpp -o gtkmm_app2 `pkg-config gtkmm-2.4 --cflags --libs`
它编译得很好,但是当我执行程序时它会崩溃。我得到以下信息:
gtkmm_app2.exe[5364]
中出现未处理的 win32 异常我不是在调试,但是当我被重定向到 Visual Studio 时,问题似乎指向一个 dll 文件:
libglibmm-2.4-1.dll
关于版本和平台的信息
编译器:
GNU C++ Compiler: 3.4.5-20060117-3
GNU C++ Compiler Runtime Library: 4.7.2-1
操作系统:
Windows XP Home Edition 2002 (Sevice Pack 3)
所以我的问题:我不知道问题取决于什么?会不会是MinGw的版本?还是操作系统导致问题?我可以在我的 C 应用程序上使用 GTK3 毫无问题地编译和执行,但不能在 C++ 上使用 gtkmm。任何想法如何解决问题?非常有帮助!
================================================ =============================
调用栈
libglibmm-2.4-1.dll!6652ea89() // it points here ..
libglibmm-2.4-1.dll!664de158()
msvcrt.dll!77c2a52e()
msvcrt.dll!77c29d60()
msvcrt.dll!77c24e2f()
msvcrt.dll!77c24e42()
libgtkmm-2.4-1.dll!0069004d()
libgtkmm-2.4-1.dll!005f0073()
并在控制台窗口中输出:似乎是某种堆损坏或分段错误:
'gtkmm_app2.exe': Loaded 'C:\cygwin\home\Ägaren\gtkmm_app2.exe', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libglibmm-2.4-1.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libglib-2.0-0.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\intl.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\user32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libgmodule-2.0-0.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libgobject-2.0-0.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libgthread-2.0-0.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libsigc-2.0-0.dll', Binary was not built with debug information.
'gtkmm_app2.exe': Loaded 'C:\gtkmm\bin\libgcc_s_sjlj-1.dll', Binary was not built with debug information.
......
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\lpk.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll', Cannot find or open the PDB file
'gtkmm_app2.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll', Cannot find or open the PDB file
Unhandled exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
First-chance exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
Unhandled exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
First-chance exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
Unhandled exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
First-chance exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
Unhandled exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
First-chance exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation writing location 0x00405068.
.......
Unhandled exception at 0x6652ea89 in gtkmm_app2.exe: 0xC0000005: Access violation
The program '[5596] gtkmm_app2.exe: Native' has exited with code 0 (0x0).
编辑:我成功地使用 VC++ (Visual Studio 2010) 编译和执行了该应用程序,因此必须是 MinGW 导致崩溃。但是我真的很想知道是什么导致了这个问题以及如何解决它。
EDIT2:在使用调试支持重新编译后,我在 cygwing 终端窗口中获得了此信息
C:\cygwin\tmp\ccIK3N1q.o: In function `main':
C:\cygwin\home\▒garen/gtkmm_app.cpp:5: undefined reference to `Gtk::Main::Main(int&, char**&, bool)'
C:\cygwin\home\▒garen/gtkmm_app.cpp:7: undefined reference to `Gtk::Window::Window(Gtk::WindowType)'
C:\cygwin\home\▒garen/gtkmm_app.cpp:9: undefined reference to `Gtk::Main::run(Gtk::Window&)'
C:\cygwin\home\▒garen/gtkmm_app.cpp:11: undefined reference to `Gtk::Window::~Window()'
C:\cygwin\home\▒garen/gtkmm_app.cpp:11: undefined reference to `Gtk::Main::~Main()'
C:\cygwin\home\▒garen/gtkmm_app.cpp:11: undefined reference to `Gtk::Window::~Window()'
C:\cygwin\home\▒garen/gtkmm_app.cpp:11: undefined reference to `Gtk::Main::~Main()'
C:\cygwin\tmp\ccIK3N1q.o: In function `_tcf_0':
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:41: undefined reference to `Glib::ustring::~ustring()'
C:\cygwin\tmp\ccIK3N1q.o: In function `_tcf_1':
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:42: undefined reference to `Glib::ustring::~ustring()'
C:\cygwin\tmp\ccIK3N1q.o: In function `_tcf_2':
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:43: undefined reference to `Glib::ustring::~ustring()'
C:\cygwin\tmp\ccIK3N1q.o: In function `_tcf_3':
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:44: undefined reference to `Glib::ustring::~ustring()'
C:\cygwin\tmp\ccIK3N1q.o: In function `_tcf_4':
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:45: undefined reference to `Glib::ustring::~ustring()'
C:\cygwin\tmp\ccIK3N1q.o:C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:46: more undefined references to `Glib::ustring::~ustring()' follow
C:\cygwin\tmp\ccIK3N1q.o: In function `_static_initialization_and_destruction_0':
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:41: undefined reference to `Glib::ustring::ustring(char const*)'
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:42: undefined reference to `Glib::ustring::ustring(char const*)'
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:43: undefined reference to `Glib::ustring::ustring(char const*)'
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:44: undefined reference to `Glib::ustring::ustring(char const*)'
C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:45: undefined reference to `Glib::ustring::ustring(char const*)'
C:\cygwin\tmp\ccIK3N1q.o:C:/gtkmm/include/gtkmm-2.4/gtkmm/papersize.h:46: more undefined references to `Glib::ustring::ustring(char const*)' follow
collect2.exe: error: ld returned 1 exit status`
正如我在第一次编辑中提到的,我可以在 Visual Studio 2010 中使用 VC++ 毫无问题地编译和执行。那么问题来了呢?
【问题讨论】:
使用调试支持重新编译;让程序崩溃,然后用它在哪里/为什么崩溃来更新你的问题。g++ -O0 -ggdb gtkmm_app2.cpp -o gtkmm_app2 'pkg-config gtkmm-2.4 --cflags --libs'
@Mark - 我更新了我的问题
使用什么编译器编译 gtkmm?可能存在不同的 ABI。
我也遇到了同样的问题,你解决了吗?我在 x86 机器上使用 gtkmm 2.22 和 mingw32
【参考方案1】:
现在我看到了调试输出,我相信你的问题是你的编译标志的顺序。我会尝试:
g++ -Wall -g `pkg-config --cflags gtkmm-2.4` gtkmm_app2.cpp -o gtkmm_app2 `pkg-config --libs gtkmm-2.4`
语法:
`pkg-config gtkmm-2.4 --cflags --libs`
不应使用。它会编译,但不会链接到外部 gtkmm 库。
【讨论】:
它不起作用 - 但我使用了我粘贴到语法中的 pkg-config 的输出。我必须这样做,因为 cygqin 出于某种原因不接受我的反引号论点。它说“无效的论点。我的解决方案并不漂亮,但应该是一样的?【参考方案2】:通常您需要单独的二进制文件用于 mingw 和 msvc。如果你使用mingw,你应该使用已经用mingw编译的gtkmm。混合编译器效果不佳。
【讨论】:
以上是关于Gtkmm 程序编译正常但崩溃 - windows XP的主要内容,如果未能解决你的问题,请参考以下文章
windows (MSYS2) 上编译的 gtkmm 程序缺少库