今日学习任务
| 1、 了解调试器gdb;(基本调试操作,段错误如何调试) 2、 了解项目管理的方法及重要性;(项目代码目录结构) 3、 熟练掌握makefile基本语法的使用;(目标、依赖、命令) 4、 企业级makefile的编写;(迭代开发) |
今日任务完成情况 | 1、2、3、4四项任务都已完成 |
今日开发中出现的问题汇总
| 不理解Makefile文件中函数 |
今日未解决问题 | 无 |
今日开发收获 | 1、 掌握了一些基本调试操作 2、 掌握了makefile基本语法的使用 |
自我评价 | 按开发规范完成了既定任务 |
其他 | 无 |
1、 调试器gdb
[root@localhost0710]# gcc -g sushu.c
[root@localhost0710]# gdb sushu
(gdb) run
(gdb) list
(gdb) break 12
(gdb) next
(gdb) step
(gdb) delete 1
(gdb) countinue
(gdb) finish
(gdb) info break
2、 工程管理器make
[root@localhost cal]# tree
.
|-- Makefile
|-- add
| |-- Makefile
| `-- src
| `-- add.c
|-- div
| |-- Makefile
| `-- src
| `-- div.c
|-- doc
|-- include
|-- main
| |-- Makefile
| `-- src
| `-- main.c
|-- mul
| |-- Makefile
| `-- src
| `-- mul.c
|-- scripts
| `-- Makefile
`-- sub
|-- Makefile
`-- src
`-- sub.c
[root@localhostcal]# vim scripts/Makefile
1CC := gcc
2CFLAGS := -Wall -O3
3Libs = -lpthread
4Target := client
5Source := $(wildcard src/*.c)
6Objs := $(patsubst %.c,%.o,$(Source))
7Modules += main add sub mul div
8AllObjs := $(addsuffix /src/*.o,$(Modules))
[root@localhost cal]# vim Makefile
1include scripts/Makefile
2
3modules_make = $(MAKE) -C $(1);
4modules_clean = $(MAKE) clean -C $(1);
5
6.PHONY: all mm mc clean
7
8all: $(Target)
9
13mm:
14 @ $(foreach n,$(Modules),$(call modules_make,$(n)))
15mc:
16 @ $(foreach n,$(Modules),$(call modules_clean,$(n)))
17
18$(Target) : mm
19 $(CC) $(CFLAGS) -o $(Target) $(AllObjs) $(Libs)
21 @ echo $(Target) make done!
22
23clean : mc
24 rm -rf $(Target)
25 @ echo clean done!
[root@localhost cal]# vim add/Makefile
1include ../scripts/Makefile
2
3all : $(Objs)
4
5clean :
6 rm -rf $(Objs)
[root@localhost cal]# make
make[1]: Entering directory`/root/cal/main'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/cal/main'
make[1]: Entering directory `/root/cal/add'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/cal/add'
make[1]: Entering directory `/root/cal/sub'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/cal/sub'
make[1]: Entering directory `/root/cal/mul'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/cal/mul'
make[1]: Entering directory `/root/cal/div'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/cal/div'
gcc -Wall -O3 -o calculator main/src/*.oadd/src/*.o sub/src/*.o mul/src/*.o div/src/*.o -lpthread
calculator make done!
[root@localhost cal]# ./calculator
add = 9
sub = 2
mul = 18
div = 2