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?
-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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With