Reputation: 101
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?
Upvotes: 7
Views: 16568
Reputation: 239
https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
The gcc documentation speaks about -g
in the compilation phase. I deduce from that, it is not needed in the link phase. Oddly enough though, the linker does not complain/warn when you it -g
.
Upvotes: 0
Reputation: 2091
-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?
Upvotes: 3