make控制源代码生成可执行程序,通过makefile实现具体的生成规则。
make规则如下:
target: dependencies
commands
target:通常是程序名称,也可以是一些执行动作
dependencies:依赖项,make会检查依赖项是否有更新,有更新的话会重新编译
command:执行命令,注意commands前面是tab缩进而不是空格
例子:
hello.c
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
return 0;
}
Makefile
hello:hello.c
gcc hello.c -o hello
运行
$ make
gcc hello.c -o hello
$ ./hello
Hello world
本文介绍如何使用make工具通过makefile来构建程序。make能够检查源文件的依赖并自动执行编译工作。文中给出一个简单的示例,展示如何为一个C语言程序设置makefile并进行编译。

被折叠的 条评论
为什么被折叠?



