Makefile是文本,不要把他当成特殊格式。
在linux下直接vim Makefile就可以了。
vim Makefile
编写makefile的步骤
- 弄清楚文件之间的依赖关系
- 编译出可执行文件,和目标文件链接起来
- 清理所有生成的目标文件和可执行文件
代码:
1 01byteorder:01byteorder.o //依赖于目标文件
2 gcc 01byteorder.o -o 01byteoeder //命令行前面要“table”符
3 01byteorder.o:01byteorder.c
4 gcc -c 01byteorder.c -o 01byteorder.o // -c 表示仅编译 -o 表示链接
//用gcc编译 .c 文件,并且和xx目标文件链接到一起。
5 clean:
6 rm -rf *.o 01byteorder //在用户输入“make clean” 命令时,清楚所有 .o 目标文件和生成的运行文件。