makefile是Linux下编译多文件程序时快捷有效的方法。主要这里展示了makefile文件的最基本用法,程序由一个.h文件和两个.cc文件构成,代码如下:
// h.h
#include <iostream>
using namespace std;
void b();
// b.cc
#include "h.h"
void b(){
cout << "this is a makefile test" << endl;
cout << "this is method b()" << endl;
}
// a.cc
#include "h.h"
int main(){
b();
return 0;
}
# Makefile
test: a.o b.o
g++ -o test a.o b.o
clean:
rm test a.o b.o
在该目录下运行make,即完成编译;运行make clean,则将所编译的目标文件和中间文件清除。