Find the answer to your Linux question:
Results 1 to 3 of 3
I am using Arch Linux. I installed X-Server, with all of its dependencies. I wrote a windows.c program using c and xlib API. I linked files, and compiled successfully. However, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2012
    Location
    Racine, Wisconsin
    Posts
    12

    Segmentation Fault after running XLib program written in C


    I am using Arch Linux. I installed X-Server, with all of its dependencies. I wrote a windows.c program using c and xlib API. I linked files, and compiled successfully. However, when I attempted to run the program, I receive a Segmentation Fault. I've been at it four hours trying to figure this out. I've gone to so many forum, to no available. Can anyone out there assist me.

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,233
    Every programmer gets segfaults! They happen all the time in new programs. And the cause is nearly always the same: you did something silly with a pointer.

    Everyone has their own way of homing in on the problem. I use diagnostic messages to determine precisely where in the program the fault occurred. For example you can have printf statements that tell you when you are entering or leaving a function. That will tell you what function crashed. Then you can use an "OK so far" printf and move it down the code gradually until it stops appearing before the crash. That will tell you what line in the function crashed. And then you can print out the actual values of suspect pointers.

    What I usually find is that some pointer turns out to be null when it ought to have had a value set. And it's always my fault; it's never the libraries!
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  3. #3
    Just Joined!
    Join Date
    Feb 2012
    Location
    Racine, Wisconsin
    Posts
    12
    Quote Originally Posted by hazel View Post
    Every programmer gets segfaults! They happen all the time in new programs. And the cause is nearly always the same: you did something silly with a pointer.

    Everyone has their own way of homing in on the problem. I use diagnostic messages to determine precisely where in the program the fault occurred. For example you can have printf statements that tell you when you are entering or leaving a function. That will tell you what function crashed. Then you can use an "OK so far" printf and move it down the code gradually until it stops appearing before the crash. That will tell you what line in the function crashed. And then you can print out the actual values of suspect pointers.

    What I usually find is that some pointer turns out to be null when it ought to have had a value set. And it's always my fault; it's never the libraries!
    Thanks Hazel,

    I've found out so far that the libraries needed aren't in the right directory. I also found that when I installed x-org server on my distro, I never specified that I wanted the development package. I'm having a difficult time finding the need Xlib header files.

    I have to make sure all of the above are in place before I can run my Xlib program.

    I will update this message when I figure out for sure what is going on.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •