认识Makefile文件
1、使用命令编译
Linux下编译c++程序。使用命令一个一个的编译cpp文件比较麻烦,因此出现了使用Makefile。
一个一个编译:
1 编译
g++ -c main.cpp -o main.o
g++ -c other.cpp -o other.o
2 链接
g++ main.o other.o -o helloworld
2、使用Makefile编译
是一个文本文件,使用命令行执行Makefile文件:
make 或者 make -f Makefile
helloworld:
g++ main.cpp other.cpp -o helloworld
Makefile语法
target:dependencies
<tab> system command
<tab> system command
<tab> system command
- target:目标
- dependencies:依赖
- tab在每一行都必须要加
- system command 系统命令
helloworld:
g++ main.cpp other.cpp -o helloworld
Clean:
rm -rf *.o helloworld
以上是两条命令;
执行make时默认执行第一个,因此要想执行后面需要使用 make Clean