Skip to content
Advertisement

Segmentation fault when executed from linux command line [closed]

My code compiles and runs fine in my IDE. However, when I use gcc to compile and then run my a.out file it says Segmentation fault (core dumped).

(edited to include my code)

In main.c I have commented out all of my code and it still causes seg fault.

JavaScript

Any ideas why? None of my other files that I include have a main method.

DEBUGGING DETAILS

JavaScript

Advertisement

Answer

We need more information. Please do the following:

  1. Recompile with “-g”, for debugging information. Include “-Wall -pedantic” for additional compiler warnings

    EXAMPLE: gcc -g -Wall -pedantic -o myprog myprog.c

  2. Update your post with your “gcc” command, and the compiler warnings you get.

  3. Run your program. If it still crashes, use gdb to analyze further:

    EXAMPLE: gdb ./myprog Type “r” to execute. Type “bt” to get a stack trace after it crashes. Copy/paste the stack trace into your post.

Here are several useful links:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement