1、gcc环境准备
gcc -v # 查看gcc版本
2、编写C程序
2.1 编写C程序 hello.c
#include <stdio.h>
int main(){
int a = 10;
int b = 10;
printf("hello world");
printf("a is %d", a)
return 0;
}
2.2 编译C程序
gcc hello.c -o hello # 编译程序
./hello # 运行程序
gcc hello.c -o hello -g # 编译程序并添加调试语句
2.3 调试语句
gdb只可调试含有调试语句的程序
gdb hello
file hello
list # 列出源文件内容,默认10行
b 5 # 在第五行打断点
r # 运行程序
r # 继续运行