Makefile规则与示例
Makefile规则与示例

1.Makefile

test : main.c sub.c sub.h
gcc -o tset main.c sub.c
2.Makefile

test : main.o sub.o
gcc -o test main.o sub.c
main.o : main.c
gcc -c -o main.o main.c
sub.o : sub.c
gcc -c -o sub.o sub.c
clean:
rm *.o test -f

执行:make make clean

3.Makefile

test : main.o sub.o
gcc -o test main.o sub.o
%.o : %.c
gcc -c -o [email protected] $<
sub.o : sub.h
clean:
rm *.o test -f

4.Makefile
Makefile规则与示例
Makefile规则与示例
#objs := a.o b.o
objs := main.o sub.o
test : $(objs)
gcc -o test main.o sub.o
#需要判断是否存在依赖文件
#最终dep_file := .a.o.d .b.o.d
dep_files := ( f o r e a c h f , (foreach f, (foreachf,(objs),.(f).d)
dep_files := $(wildcard KaTeX parse error: Expected 'EOF', got '#' at position 14: (dep_files)) #̲把依赖文件包含进来 ifnep…(dep_files),)
%.o : %.c
gcc -Wp,-MD,[email protected] -c -o [email protected] $<
clean:
rm *.o test -f

相关文章: