Compiling C/C++ Programs For gdb Support
Originally written by
- An executable program needs to have "debug symbols" in order to be
properly debugged under gdb.
- To compile a single-file program with debug info, use the '-g' flag:
gcc -g prog.c -o prog
- The same manner works with g++ for C++ programs.
- Use '-g' also when compiling separate source files of a multi-file
- You don't need to compile all source files of a program with debug
- ... but then you'll only be able to step through the sources that were
compiled with '-g'.