-1

My college uses a linux os, we can start xserver and then empty gui will appear, i wrote program to display a line, i compiled the code it 's fine. but when i execute the program it shows segmentation fault, how to execute the program in gui??

user767060
  • 21
  • 1
  • 7

1 Answers1

1

If your program segfaults, it probably has nothing to do with the GUI. You are probably attempting to access memory you weren't granted.

For your question on how to program a GUI, my best suggestion would be to use a library like Qt or GTK to abstract away the hard, strange Xserver code.

3Doubloons
  • 2,088
  • 14
  • 26
  • But mostly, your question needs to be more specific if you want anything more helpful than this. – 3Doubloons Jun 09 '11 at 12:12
  • My openDisplay always returns null . – user767060 Jun 09 '11 at 12:55
  • Then your Segfault most likely comes from trying to use that NULL as a valid display. Please edit some code showing how you prepare for your openDisplay in the question. – 3Doubloons Jun 09 '11 at 13:54
  • 1
    XOpenDisplay returns NULL when you can't connect to the X server, either because you specified a DISPLAY that doesn't exist/isn't running, or don't have permission to connect to the display. You need to check the return value for NULL and handle it - trying to use it will result in a segfault, which is a bug in your program. – alanc Jun 09 '11 at 21:02