基本编译调试及Makefile总结

1.gcc -g test.c -o test
gdb test     #启动GDB调试
break(b) 函数名/行号/文件名:行号/行号if条件       #添加断点
info break 查看所有断点
delete 断点编号
run
next(n)...next(不进入子函数)
step(s)...(进入子函数)
continue(c)继续运行程序
list(l)             #查看程序
print(p)变量名
finish
watch变量名
quit(q)

2.Makefile文件
目标?依赖?命令
hello:main.o fun1.o fun2.o
    gcc main.o fun1.o fun2.o -o hello
main.o:main.c
    gcc -c main.c
fun1.0:fun1.c
    gcc -c fun1.c
...
.PHONY:clean        #伪目标

改进:
obj=main.o fun1.o fun2.o
hello:$(obj)
    gcc $(obj) -o hello
    @gcc $(obj) -o hello #加@取消回显
$^:代表所有依赖文件
$@:代表目标
$<:代表第一个依赖文件

clean:
    rm -f hello main.o fun1.o fun2.o
make命令默认寻找makefile或Makefile文件
make -f 文件名

posted @ 2014-11-10 17:59  ht-beyond  阅读(418)  评论(0编辑  收藏  举报