前阵子让写makefile,纠结了下,基本忘记差很少了。ui
1.gcc的编译选项spa
-c命令行 |
只是编译不连接,生成目标文件“.o”调试 |
-Sci |
只是编译不汇编,生成汇编代码get |
-E编译器 |
只进行预编译,不作其余处理编译 |
-gtable |
在可执行程序中包含标准调试信息class |
-o file |
把输出文件输出到file里 |
-v |
打印出编译器内部编译各过程的命令行信息和编译器的版本 |
-I dir |
在头文件的搜索路径列表中添加dir目录 |
-L dir |
在库文件的搜索路径列表中添加dir目录 |
-static |
连接静态库 |
-llibrary |
链接名为library的库文件 |
2.makefile的规则
target...: prerequire...
command
看到这个就熟悉了
3. makefile的文件中有什么
a)依赖的部分include
b)变量定义
c)显示规则(你所直观看到的依赖)
d)隐式规则(偷懒依靠makefile语法省写的那部分)
e)注释#
4.makefile 的工做步骤:
a)读取makefile
b)读include
c)初始化文件中的变量
d)推导隐式规则
e)为全部目标创建依赖链
f)根据依赖链,决定生成哪些目标
g) 执行生成命令
5.最简单的demo
target=hellotarget_o=hello.otarget_c=hello.c$(target):$(target_o) cc -o $(target) $(target_o)$(target_o):$(target_c) cc -c $(target) $(target_c)