简单带子目录的makefile练习
简单带子目录的makefile练习
开始学linux。我练习写的第一个带子目录的makefile文件。 1。建立文件夹 wulong wulong中含 三个文件夹 include source pro 和makefile文件。 include 中包含 hai.h头文件。
source 中包含 hello.c文件。
pro 中包含 haia.c haib.c文件。
makefile文件内容有两种写法:
makefile 第一种写法:
//*********************
CC=gcc #选择编译器类型为gcc
VPATH= include : pr : source #列明文件存放目录
hello: hello.o haia.o haib.o
$(CC) -o hello hello.o haia.o haib.o
hello.o:hello.c hai.h
$(CC) -c hello.c
haia.o: haia.c hai.h
$(CC) -c haia.c
haib.o: haib.c hai.h
$(CC) -c haib.c .PHONY: clean clean: rm hello $(obj) //*************************
makefile第二种写法(简化版):
//******************************** CC=gcc #选择编译种类
VPATH= include : pr : source #在include pr source 三目录下查找文件
obj= hello.o haia.o haib.o #
hello:$(obj) #
$(CC) -o hello $(obj)
$(obj): hai.h
.PHONY: clean
clean: