首先基于上篇文章makefile 的初认识,我们继续学习makefile 新东西(hello.cpp test.h文件和上文类同不在细谈)着重学习makefile;
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
同样建立操做和三个文件
#include<iostream>
using namespace std;
void print()
{cout<<"i am a student"<<endl;}
test.h文件
#include"../function/test.h"
#include<iostream>
using namespace std;
int main(int argc,char* argv[])
{cout<<"hello world"<<endl;
print();
return 0;
}
hello.cpp文件
VPATH=./source
CC=g++
#vpath %.cpp source
#vpath %.h function
object=hello.o
hello:$(object)
@ echo 正在编译文件 $<
$(CC) -o $@ -g $^
$(object):hello.cpp