Hind Forsum Hind Forsum - 3 months ago 33
Linux Question

gcc: what's the difference between "-g" and "-ggdb"?

I am working under linux, it seems to me that the effect of "-g" and "-ggdb" are no much difference. I only find using "-ggdb" will generate binary several bytes bigger.

So what's the core difference that gdb should have one "-g" option and another "-ggdb" option?



The compiled program should be stored at some where, for the debuggers (GDB here) to look into it and follow.

This is technically called as "Debugging data format".

Some universaslly accepted debugging data formats are (there are some more):

COFF - Common Object File Format - on UNIX like systems.

PE/COFF - Portable Executable - pretty famous on windows, usually dotnet uses it.

DWARF - popular on UNIX like systems.


The GDB options you asked in your question are related to generating these debugging data formats.

Based on documenation the funcdamental difference is: option "g" provides the debugging data in particular system's native format. option "-ggdb" is bit rich and expensive. provides the debugging data in most expressive format available.