C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-01-2009, 05:38 PM   #1
Registered User
 
Join Date: Jan 2009
Posts: 156
Segmentation fault ith g_type_check_class_cast () from /usr/lib/libgobject-2.0.so.0

Hi,
I am using opencv and gtk libraries. After compiling with: gcc -Wall -g `pkg-config --cflags --libs opencv` `gtk-config --cflags --libs` -o helloworld main.c, I now get a Segmentation fault problem while running my executable. Examination of the core file gives the information:

Can't read pathname for load map: Input/output error

Reading symbols from /usr/lib/libcxcore.so.1...done.
Loaded symbols for /usr/lib/libcxcore.so.1
Reading symbols from /usr/lib/libcv.so.1...done.
Loaded symbols for /usr/lib/libcv.so.1
Reading symbols from /usr/lib/libhighgui.so.1...done.
Loaded symbols for /usr/lib/libhighgui.so.1
Reading symbols from /usr/lib/libcvaux.so.1...done.
Loaded symbols for /usr/lib/libcvaux.so.1
Reading symbols from /usr/lib/libml.so.1...done.
Loaded symbols for /usr/lib/libml.so.1
Reading symbols from /usr/lib/libgtk-1.2.so.0...done.
Loaded symbols for /usr/lib/libgtk-1.2.so.0
Reading symbols from /usr/lib/libgdk-1.2.so.0...done.
Loaded symbols for /usr/lib/libgdk-1.2.so.0
Reading symbols from /usr/lib/libgmodule-1.2.so.0...done.
Loaded symbols for /usr/lib/libgmodule-1.2.so.0
Reading symbols from /usr/lib/libglib-1.2.so.0...done.
Loaded symbols for /usr/lib/libglib-1.2.so.0
Reading symbols from /lib/tls/i686/cmov/libdl.so.2...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libdl-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libdl.so.2
Reading symbols from /usr/lib/libXi.so.6...done.
Loaded symbols for /usr/lib/libXi.so.6
Reading symbols from /usr/lib/libXext.so.6...done.
Loaded symbols for /usr/lib/libXext.so.6
Reading symbols from /usr/lib/libX11.so.6...done.
Loaded symbols for /usr/lib/libX11.so.6
Reading symbols from /lib/tls/i686/cmov/libm.so.6...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libm-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libm.so.6
Reading symbols from /lib/tls/i686/cmov/libc.so.6...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libc-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /usr/lib/libstdc++.so.6...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /usr/lib/libgomp.so.1...done.
Loaded symbols for /usr/lib/libgomp.so.1
Reading symbols from /lib/tls/i686/cmov/libpthread.so.0...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libpthread-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libpthread.so.0
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /usr/lib/libgthread-2.0.so.0...done.
Loaded symbols for /usr/lib/libgthread-2.0.so.0
Reading symbols from /lib/tls/i686/cmov/librt.so.1...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/librt-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/librt.so.1
Reading symbols from /usr/lib/libgtk-x11-2.0.so.0...done.
Loaded symbols for /usr/lib/libgtk-x11-2.0.so.0
Reading symbols from /usr/lib/libgdk-x11-2.0.so.0...done.
Loaded symbols for /usr/lib/libgdk-x11-2.0.so.0
Reading symbols from /usr/lib/libatk-1.0.so.0...done.
Loaded symbols for /usr/lib/libatk-1.0.so.0
Reading symbols from /usr/lib/libpangoft2-1.0.so.0...done.
Loaded symbols for /usr/lib/libpangoft2-1.0.so.0
Reading symbols from /usr/lib/libpangocairo-1.0.so.0...done.
Loaded symbols for /usr/lib/libpangocairo-1.0.so.0
Reading symbols from /usr/lib/libgio-2.0.so.0...done.
Loaded symbols for /usr/lib/libgio-2.0.so.0
Reading symbols from /usr/lib/libcairo.so.2...done.
Loaded symbols for /usr/lib/libcairo.so.2
Reading symbols from /usr/lib/libpango-1.0.so.0...done.
Loaded symbols for /usr/lib/libpango-1.0.so.0
Reading symbols from /usr/lib/libfreetype.so.6...done.
Loaded symbols for /usr/lib/libfreetype.so.6
Reading symbols from /usr/lib/libfontconfig.so.1...done.
Loaded symbols for /usr/lib/libfontconfig.so.1
Reading symbols from /usr/lib/libgdk_pixbuf-2.0.so.0...done.
Loaded symbols for /usr/lib/libgdk_pixbuf-2.0.so.0
Reading symbols from /usr/lib/libgobject-2.0.so.0...done.
Loaded symbols for /usr/lib/libgobject-2.0.so.0
Reading symbols from /usr/lib/libgmodule-2.0.so.0...done.
Loaded symbols for /usr/lib/libgmodule-2.0.so.0
Reading symbols from /usr/lib/libglib-2.0.so.0...done.
Loaded symbols for /usr/lib/libglib-2.0.so.0
Reading symbols from /usr/local/lib/libpng12.so.0...done.
Loaded symbols for /usr/local/lib/libpng12.so.0
Reading symbols from /usr/local/lib/libjpeg.so.62...done.
Loaded symbols for /usr/local/lib/libjpeg.so.62
Reading symbols from /usr/lib/libz.so.1...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /usr/lib/libtiff.so.4...done.
Loaded symbols for /usr/lib/libtiff.so.4
Reading symbols from /usr/lib/libjasper.so.1...done.
Loaded symbols for /usr/lib/libjasper.so.1
Reading symbols from /usr/lib/i686/cmov/libavformat.so.52...done.
Loaded symbols for /usr/lib/i686/cmov/libavformat.so.52
Reading symbols from /usr/lib/i686/cmov/libavcodec.so.51...done.
Loaded symbols for /usr/lib/i686/cmov/libavcodec.so.51
Reading symbols from /usr/lib/libraw1394.so.8...done.
Loaded symbols for /usr/lib/libraw1394.so.8
Reading symbols from /usr/lib/libtheora.so.0...done.
Loaded symbols for /usr/lib/libtheora.so.0
Reading symbols from /usr/lib/libvorbisenc.so.2...done.
Loaded symbols for /usr/lib/libvorbisenc.so.2
Reading symbols from /usr/lib/i686/cmov/libavutil.so.49...done.
Loaded symbols for /usr/lib/i686/cmov/libavutil.so.49
Reading symbols from /usr/lib/libvorbis.so.0...done.
Loaded symbols for /usr/lib/libvorbis.so.0
Reading symbols from /usr/lib/libogg.so.0...done.
Loaded symbols for /usr/lib/libogg.so.0
Reading symbols from /lib/ld-linux.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.8.90.so...done.
done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /usr/lib/libXau.so.6...done.
Loaded symbols for /usr/lib/libXau.so.6
Reading symbols from /usr/lib/libxcb-xlib.so.0...done.
Loaded symbols for /usr/lib/libxcb-xlib.so.0
Reading symbols from /usr/lib/libxcb.so.1...done.
Loaded symbols for /usr/lib/libxcb.so.1
Reading symbols from /usr/lib/libXcomposite.so.1...done.
Loaded symbols for /usr/lib/libXcomposite.so.1
Reading symbols from /usr/lib/libXdamage.so.1...done.
Loaded symbols for /usr/lib/libXdamage.so.1
Reading symbols from /usr/lib/libXfixes.so.3...done.
Loaded symbols for /usr/lib/libXfixes.so.3
Reading symbols from /usr/lib/libXrender.so.1...done.
Loaded symbols for /usr/lib/libXrender.so.1
Reading symbols from /usr/lib/libXinerama.so.1...done.
Loaded symbols for /usr/lib/libXinerama.so.1
Reading symbols from /usr/lib/libXrandr.so.2...done.
Loaded symbols for /usr/lib/libXrandr.so.2
Reading symbols from /usr/lib/libXcursor.so.1...done.
Loaded symbols for /usr/lib/libXcursor.so.1
Reading symbols from /lib/libselinux.so.1...done.
Loaded symbols for /lib/libselinux.so.1
Reading symbols from /usr/lib/libpixman-1.so.0...done.
Loaded symbols for /usr/lib/libpixman-1.so.0
Reading symbols from /usr/lib/libxcb-render-util.so.0...done.
Loaded symbols for /usr/lib/libxcb-render-util.so.0
Reading symbols from /usr/lib/libxcb-render.so.0...done.
Loaded symbols for /usr/lib/libxcb-render.so.0
Reading symbols from /usr/lib/libexpat.so.1...done.
Loaded symbols for /usr/lib/libexpat.so.1
Reading symbols from /lib/libpcre.so.3...done.
Loaded symbols for /lib/libpcre.so.3
Reading symbols from /usr/lib/libgsm.so.1...done.
Loaded symbols for /usr/lib/libgsm.so.1
Reading symbols from /usr/lib/libXdmcp.so.6...done.
Loaded symbols for /usr/lib/libXdmcp.so.6
Reading symbols from /lib/tls/i686/cmov/libnss_compat.so.2...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libnss_compat-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libnss_compat.so.2
Reading symbols from /lib/tls/i686/cmov/libnsl.so.1...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libnsl-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libnsl.so.1
Reading symbols from /lib/tls/i686/cmov/libnss_nis.so.2...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libnss_nis-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libnss_nis.so.2
Reading symbols from /lib/tls/i686/cmov/libnss_files.so.2...Reading symbols from /usr/lib/debug/lib/tls/i686/cmov/libnss_files-2.8.90.so...done.
done.
Loaded symbols for /lib/tls/i686/cmov/libnss_files.so.2
Core was generated by `./helloworld'.
Program terminated with signal 11, Segmentation fault.
[New process 9452]
#0 0xb7028485 in g_type_check_class_cast () from /usr/lib/libgobject-2.0.so.0
(gdb)

How can I solve it? Thanks a lot!
lehe is offline   Reply With Quote
Old 02-01-2009, 05:42 PM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
If you type "where" at the gdb prompt, you should get a stack-backtrace, which should show you where you're doing the cast that goes wrong.

Most likely, it's a dynamic_cast<...>(...) that is the culprit, and most likely becase you are doing somehing strange like casting a null-pointer or some other invalid pointer.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 02-01-2009, 06:00 PM   #3
Registered User
 
Join Date: Jan 2009
Posts: 156
Thank you very much!
I am trying my luck if you or someone know how to fix the problem. Here is the information that I got:
Code:
(gdb) where
#0  0xb7028485 in g_type_check_class_cast () from /usr/lib/libgobject-2.0.so.0
#1  0xb7cf5f18 in ?? () from /usr/lib/libhighgui.so.1
#2  0xb7bc0628 in ?? () from /usr/lib/libgtk-1.2.so.0
#3  0xb7bc0848 in gtk_type_class () from /usr/lib/libgtk-1.2.so.0
#4  0xb7bc0ac2 in gtk_type_new () from /usr/lib/libgtk-1.2.so.0
#5  0xb7cf66e4 in cvImageWidgetNew () from /usr/lib/libhighgui.so.1
#6  0xb7cf68af in cvNamedWindow () from /usr/lib/libhighgui.so.1
#7  0x0804894e in main (argc=Cannot access memory at address 0x0
) at main.c:24
My code is
Code:
int main( int argc, char** argv )
{
  // Set up variables
  CvFont font;
  CvPoint pt;
  CvScalar colour;
  CvSize text_size;
  char window_name[] = "Hello World!";
  int line_type = CV_AA; // change it to 8 to see non-antialiased graphics
  int width = 1000, height = 700;

  // Create an image
  IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 );

  // Create a window
  cvNamedWindow(window_name, 1 );

  ...
If I step over the line using cvNameWindow, I would get
Code:
Breakpoint 3, main (argc=Cannot access memory at address 0x201000
) at main.c:24
24	  cvNamedWindow(window_name, 1 );
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0xb70d6485 in g_type_check_class_cast () from /usr/lib/libgobject-2.0.so.0

Last edited by lehe; 02-01-2009 at 06:02 PM.
lehe is offline   Reply With Quote
Old 02-01-2009, 06:10 PM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Yes, the crash happens inside the call to cvNamedWindow() - in fact, I'd say cvImageWidgetNew is a likely candidate. But the problem is most likely that you pass something wrong into it.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 02-01-2009, 06:23 PM   #5
Registered User
 
Join Date: Jan 2009
Posts: 156
A little bit update.
I just compile and run with the same code in Visual C++. All is fine. But in Linux, I got Segmentation Fault.
Could it be another possibility: the library opencv, gtk or glib in my Linux is impaired?
lehe is offline   Reply With Quote
Old 02-02-2009, 12:00 AM   #6
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
A couple of points.
1. Why is argc in main so screwed up already, even in a simple program.

2. I see you called the program main.c (a C program), yet I thought gtk was a C++ library.
This means that you probably haven't called all the global constructors yet.
http://www.parashift.com/c++-faq-lit...c-and-cpp.html
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 02-02-2009, 01:33 AM   #7
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,365
Quote:
Originally Posted by Salem
2. I see you called the program main.c (a C program), yet I thought gtk was a C++ library.
Gtkmm is the C++ wrapper of the C library known as GTK+.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Old 02-02-2009, 07:27 AM   #8
Registered User
 
Join Date: Jan 2009
Posts: 156
Ah, my mistake. I have two versions of gtk on my system. I used "gtk-config --cflags --libs', which provides info of gtk-1.2 and results in the previous error. But the error goes away when I use the info provided by "pkg-config --cflags --libs gtk+-2.0'. All I can guess is that the opencv library I am using depends on gtk+-2.0 with new features not present in gtk-1.2.

I think I might accidentally install gtk-1.2 myself and want to uninstall it. How to check if it is not in used by other programs and safe to uninstall? I find that I cannot uninstall them by "sudo apt-get remove gtk-1.2", or "sudo apt-get remove gtk+-1.2", or "sudo apt-get remove gtk1.2". It is hard for me to identify what exactly to uninstall. Even searching synaptics software manager in my ubuntu system, there will be so many software associated with "gtk 1.2", making me uncertain what to remove.

I also noticed the info of gtk-1.2 cannot be retrieved by pkg-config but by gtk-config, something that looks so specific, while gtk+-2.0 only works with pkg-config not with gtk-config. Looks like gtk-1.2 has a file called gtk-config while gtk+- 2.0 gtk+-2.0.pc. Another library libpng can be used in both "libpng-config --cflags --libs" and "pkg-config --cflags --libs libpng". What's the point that things are so different for different libraries and even same library but different versions?

Last edited by lehe; 02-02-2009 at 07:40 AM.
lehe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Segmentation fault turkish_van C Programming 8 01-20-2007 05:50 PM
Segmentation fault bennyandthejets C++ Programming 7 09-07-2005 05:04 PM
Segmentation fault NoUse C Programming 4 03-26-2005 03:29 PM
Locating A Segmentation Fault Stack Overflow C Programming 12 12-14-2004 01:33 PM
Segmentation fault... alvifarooq C++ Programming 14 09-26-2004 12:53 PM


All times are GMT -6. The time now is 08:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22