0

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?

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.