首先基于上篇文章makefile 的初认识,我们继续学习makefile 新东西(hello.cpp test.h文件和上文类同不在细谈)着重学习makefile,大型工程中存在很多文件夹,他们分别代表不同的功能,因此,我们 需要划分文件功能,讨论一下makefile;文件百度云盘(http://pan.baidu.com/s/1geVQJx5)
mkdir -p test
cd test
mkdir function
touch hello.cpp
vi hello.cpp
mkdir source
touch test.h
vi test.h
cd ..
touch makefile
vi makefile
上述过程为建立新的文件夹,还是来看一下makefile 里面又出现了什么新知识;
VPATH=./source
CC=g++
#vpath %.cpp source
#vpath %.h function
object=hello.o
hello:$(object)
$(CC) -o $@ -g $<
$(object):hello.cpp
$(CC) -o $@ -c $<
clean:
-rm hello $(object)
上述的makefile文件应该位于test文件夹下;
VPATH=./source
#vpath %.cpp source
#vpath %.h function
VPATH 是makefile的系统路径变量 它用来指明,在make解析makefile时候,发现所需要的源文件在source文件夹下,这是