在终端新建四个文件test.h,test.cpp,main.cpp,makefile文件
vi test.h
vi test.cpp
vi main.cpp
vi makefile
test.h内容
#ifndef TEST_H
#define TEST_H
void hello();
#endif
test.cpp内容
#include "test.h"
#include<stdio.h>
void hello()
{
printf("Hello world\n");
}
makefile文件内容
main:main.o test.o
g++ -o main main.o test.o
main.o:main.cpp
g++ -c main.cpp
test.o:test.h test.cpp
g++ -c test.cpp
clean:
rm -f *.o main
在终端执行make main
可发现目录下生成了mian,main.o,test.o文件
执行make clean删除.o文件以及main