-1

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.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pthread.h>


#include "BmpProcessor.h"
#include "PixelProcessor.h"
#include "PpmProcessor.h"
#include "debug.h"

#define THREAD_COUNT 8;

int main(int argc, char *argv[]) {

/** commented out all of my code */
    
    return 0;
}

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

DEBUGGING DETAILS

gcc -g -Wall -pedantic -o PurdyImageProcessor PurdyImageProcessor.c BmpProcessor.c PpmProcessor.c PixelProcessor.c -lm -pthread
PixelProcessor.c: In function ‘boxBlurMultithreading’:
PixelProcessor.c:437:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
PixelProcessor.c: In function ‘cheesifyMultithreading’:
PixelProcessor.c:487:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
Michael
  • 55
  • 1
  • 7
  • 2
    You've given us NO information relevant to your program. Most likely you're triggering undefined behavior, but there's no way to know for sure without seeing the code. Also, try running your code through valgrind. If you're mismanaging memory it will tell you where. – dbush Apr 03 '21 at 21:39
  • 1
    You probably have undefined behavior that express itself by using a different compiler. Here is how to trouble shoot it. Compile your program with debugging symbols (i.e. -g2) then `ulimit -c unlimited` to get a core file next time you run it. Then analyze the core file with `gdb binary core` Or, as @CharlesDuffy points out, after you compile the binary with debugging symbols run it under gdb with: `gdb binary` or you attach to it's pid if you have the opportunity before it crashes. – Allan Wind Apr 03 '21 at 21:39
  • 2
    Don't need a core dump if you attach a debugger during initial execution. – Charles Duffy Apr 03 '21 at 21:40
  • 1
    @CharlesDuffy yeah, good point, and it gives you a live process. Not used to that luxury. – Allan Wind Apr 03 '21 at 21:41
  • 1
    Updated with my debug. – Michael Apr 03 '21 at 22:01

1 Answers1

2

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:

paulsm4
  • 114,292
  • 17
  • 138
  • 190