Gtkmm program compiles fine but crashes - windows

2019-05-21 02:38发布

问题:

I have recently installed gtkmm (gtkmm-2.4)

when I compile with g++ I use the following information from pkg-config

headerfiles

pkg-config gtkmm-2.4 --cflags

objectfiles

pkg-config gtkmm-2.4 --libs

So i compile I simple helloworld problam that is to show a window on the screen ...

g++ gtkmm_app2.cpp -o gtkmm_app2 `pkg-config gtkmm-2.4 --cflags --libs`

It compiles fine but when I execute the program it chrashes. I get the following information:

An unhandled win32 exception occurred in gtkmm_app2.exe[5364]

I am not an exert on debugging but when I get redirected to Visual Studio the problems seems to point to a dll-file:

 libglibmm-2.4-1.dll

Information about versions and platforms

Compiler:

GNU C++ Compiler: 3.4.5-20060117-3
GNU C++ Compiler Runtime Library: 4.7.2-1

OS:

 Windows XP Home Edition 2002 (Sevice Pack 3)

So My Question: I have no idea what the problems depends on? Could it be the version of MinGw? Or is it the Operating system causing the problem? I can compile and execute without problems using GTK3 on my C-apps, but NOT gtkmm with c++. Any Ideas how to solve the problem(s)? Extremely helpful for help this!!!

==========================================================================

The call stack

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()   

And output in the consolewindow: It seems to be some kind if heapcorruption or segmentation fault:

'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).

EDIT: I succeeded in compiling and execute the app with VC++ (Visual Studio 2010) so it must be MinGW that is responsible for the crash. But I would really like to know WHAT it is that cause the problem and HOW to solve it.

EDIT2: after recompiling with debug support I got this info in cygwing terminalwindow

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`

As I mentioned in the first edit is that I can compile and execute with VC++ in Visual Studio 2010 without problem. So what is the problem then?

回答1:

Now that I see the debug output, I believe your problem is the order of your compile flags. I would try:

g++ -Wall -g `pkg-config --cflags gtkmm-2.4` gtkmm_app2.cpp -o gtkmm_app2 `pkg-config --libs gtkmm-2.4`

The syntax:

`pkg-config gtkmm-2.4 --cflags --libs`

should not be used. It'll compile but not link to the external gtkmm libraries.



回答2:

Usually you need separate binaries for mingw and msvc. If you use mingw, you should use gtkmm that has been compiled with mingw. mixing compilers doesnt work very well.