Home > Enterprise >  GDB error - not in executable format: file format not recognized
GDB error - not in executable format: file format not recognized

Time:09-21

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?

CodePudding user response:

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

  • Related