make命令简介

1. 简介

Compiling is the act of turning source code into object code. Linking is the act of combining object code with libraries into a raw executable. Building is the sequence composed of compiling and linking, with possibly other tasks such as installer creation.

编译是将源代码转换为目标代码的行为。链接是将目标代码与库组合成原始可执行文件的行为。构建是由编译链接组成的序列,可能还有其他任务,如创建安装程序。

The GNU make utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them.

GNU make 实用程序,它自动确定需要重新编译大型程序的哪些部分,并发出重新编译它们的命令。

make 是C语言的项目最常用的构建build)工具。实际上,任何只要某个文件有变化,就要重新构建的项目,都可以用 make 构建。

You need a file called a makefile to tell make what to do. Most often, the makefile tells make how to compile and link a program.

你需要一个名为 makefile 的文件来告诉make该做什么。通常,makefile 会告诉make 如何编译链接程序。

2. 基本书写规则

一个简单的makefile由以下的“规则”组成:

target … : prerequisites …
<\tab>recipe
        …
        …
  1. target 通常是由程序生成的文件的名称;目标的示例是可执行文件 .out 或对象文件 .o。目标也可以是要执行的操作的名称(phony target,伪目标),例如 clean
  2. prerequisites(前置条件)是一个用作创建目标的输入的文件。一个目标通常依赖于多个 .c.h 文件。
  3. recipe 是一种执行的动作。一个 recipe 可能有多个命令,可以在同一行上,也可以在各自的行上。每个recipe行的开头都是一个制表符 <tab>

通常,一个recipe在一个有前置条件的规则中,如果任何前置条件发生变化,它将用于创建一个target文件。相反,不需要有前置条件。例如

相关推荐

  1. make命令简介

    2024-04-08 04:26:01       15 阅读
  2. Android make命令简述

    2024-04-08 04:26:01       11 阅读
  3. make命令

    2024-04-08 04:26:01       10 阅读
  4. Linux命令详解./configure、makemake install 命令学习

    2024-04-08 04:26:01       36 阅读
  5. shared_ptr 和 make_shared 简介

    2024-04-08 04:26:01       35 阅读
  6. Linux常见命令简介

    2024-04-08 04:26:01       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-08 04:26:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-08 04:26:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-08 04:26:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-08 04:26:01       18 阅读

热门阅读

  1. 大学课堂点名程序

    2024-04-08 04:26:01       13 阅读
  2. Docker 入门

    2024-04-08 04:26:01       14 阅读
  3. 【Qt\C++】二维图形化故障树

    2024-04-08 04:26:01       12 阅读
  4. 洛谷 P3512 [POI2010] PIL-Pilots

    2024-04-08 04:26:01       12 阅读
  5. 06-kafka配置

    2024-04-08 04:26:01       10 阅读
  6. 出国留学哪个国家好又便宜

    2024-04-08 04:26:01       46 阅读
  7. Redis

    Redis

    2024-04-08 04:26:01      18 阅读