GDB error – not in executable format: file format not recognized

Issue

I’m trying to use gdb with a simple hello world program, but having some trouble

hello.c

#include <stdio.h>
int main()
{
   printf("Hello World");
   return 0;
}

I then compile using the following two commands:

gcc -o hello.o hello.c

gcc -g -o hello.o hello.c

But when I type gdb hello.c I get an error:
"/home/myName/hello.c": not in executable format: file format not recognized

Does anybody know why this may be?

Solution

You need to run and debug the executable not the source file. And executables by common convention should not have .o as those are for intermediate objects. So try: gcc -g -o hello hello.c && gdb ./hello

Answered By – kaylum

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published