target : *.o
g++ -o target *.o
*.o: *.c
g++ -c *.o *.c *.h
=======================
# a sample
# makefile ver2.0 4/22/2014 add macro
# $@ name of the target
# $^ name of all prerequisites with duplicates removed
# $< name of the first prerequisite
CC = g++
all: Calc clean
Calc: InsrFund.o calc.o
$(CC) -o Calc calc.o InsrFund.o
calc.o: calc.cpp InsrFund.h
$(CC) -c calc.cpp
InsrFund.o: InsrFund.cpp InsrFund.h
$(CC) -c InsrFund.cpp
clean:
rm *.o Calc
~
本文介绍了一个具体的Makefile示例,展示了如何通过Makefile来自动化编译C++源代码文件,包括目标文件的生成和最终可执行文件的链接过程。通过定义规则和依赖关系,可以有效地管理项目的编译流程。
3202

被折叠的 条评论
为什么被折叠?



