Abstract
GDB(from GNU) is a command line tool to debug your programs step by step.
GCC is GNU Compiler Collection. it could compile many languages, including c, c++, java, fortran, pascal, etc.
gcc/g++
GCC contains both gcc and g++.
And actully they have common for compiling c++.
Differences are:
- gcc is GNU C Compiler, gcc would *.c as c file, and treat *.cc as cpp file(grammer has difference).
- g++ is GNU C++ Compiler, g++ would treat both *.c and *.cc as cpp file. and g++ would link STL by default.
So the suggestion is compile c project with gcc, compile c++ project with g++.
Some useful compile options shown as below, assuming source file is main.cc.
preprocessing with -E
1
g++ -E -o main.i main.cc
compiling to assembly code with -S
1
g++ -S -o main.s main.cc
compiling to machine code with -c
1
g++ -c -o main.o main.cc
link to machine code without option
1
g++ -o main.out main.o
the most common usage: combination of compiling to machine code and link machine code
1
g++ -o main.out main.cc
gdb
in order to apply gdb, you need to insert debug information when compiling with -g option.
1 | g++ -g -o main.out main.cc |
useful command for gdb
1 | gdb 常用命令 |