<p>什么是makefile? 如何编写makefile? <br />
makefile:一个文本形式的文件,其中包含一些规则告诉make编译哪些文件以及怎样编译这些文件,每条规则包含以下内容:<br />
一个target,即最终创建的东西<br />
一个和多个dependencies列表,通常是编译目标文件所需要的其他文件<br />
需要执行的一系列commands,用于从指定的相关文件创建目标文件<br />
<br />
make执行时按顺序查找名为GNUmakefile,makefile或者Makefile文件,通常,大多数人常用Makefile<br />
Makefile规则:<br />
target: dependency dependency [..] command command [..]<br />
注意:command前面必须是制表符<br />
例子:<br />
editor: editor.o screen.o keyboard.o<br />
gcc -o editor editor.o screen.o keyboard.o<br />
editor.o : editor.c editor.h keyboard.h screen.h<br />
gcc -c editor.c<br />
screen.o: screen.c screen.h<br />
gcc -c screen.c<br />
keyboard.o : keyboard.c keyboard.h<br />
gcc -c keyboard.c<br />
clean:<br />
rm editor *.o<br />
<br />
同类其他面试题 点击</p>