Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug Flag With GCC (compile phase / link phase)

I have a this Makefile

application=<somebinaryname>
CXXFLAGS=-g -std=c++14 -Wall -Werror -pedantic
LDFLAGS=-g

auto: $(application)

$(application): main.o aaa.o aab.o aba.o baa.o
        $(CXX) $(LDFLAGS) -o $@ $^

%.o: %.cpp
        $(CXX) $(CXXFLAGS) -c $< -o $@

# rest of Makefile not relevant to my question

Can someone please tell me if the -g option is supposed to go during the compilation phase (with CXXFLAGS) or during the link phase (with LDFLAGS)? I looked for examples and documentation everywhere, but they all have very trivial examples like (even the manpage):

gcc -g -o binary source.cpp

I get that, but it doesn't tell me much.

Any more clarity on this?

like image 564
Novice User Avatar asked Nov 08 '22 07:11

Novice User


1 Answers

-g produces debugging information. Compile your C program with -g option. This allows the compiler to collect the debugging information. Then you can use gdb to debug the binary.

Some useful links

http://www.thegeekstuff.com/2010/03/debug-c-program-using-gdb/

https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html

GCC -g vs -g3 GDB Flag: What is the Difference?

like image 50
ganeshredcobra Avatar answered Nov 14 '22 21:11

ganeshredcobra