Hey folks, have you ever used IDEs? Most probably, yes. So what's your favorite one? Geany, CodeBlocks, DevC++, Eclipse, NetBeans or something else?

大家好,您曾经使用过IDE吗? 很有可能,是的。 那你最喜欢哪一个呢? Geany,CodeBlocks,DevC ++,Eclipse,NetBeans或其他?

We use IDEs for sake of ease and quick coding. What if I tell you it is making you dumber at programming because it is as it hides a lot of background details from us so this article is about it only.

我们使用IDE是为了方便快捷地进行编码。 如果我告诉您,这会使您在编程上变得笨拙,那是因为它隐藏了我们很多背景细节,因此本文仅是关于它的。

You might say ‘Hey I used the terminal on Linux and I know it's compilation done' trust me I don't mean that. You might be aware with g++ compiler or GCC (GNU C Compiler) perhaps CC (Clang's Compiler) or any other compilers (for other languages too) but it is only for one single source code and what about if you are working on a project with multiple source code and having dependencies, and need to update every time any file updates other files also need to update here make comes handy.

您可能会说:“嘿,我在Linux上使用了终端,我知道它已经完成编译了”,相信我,我不是那个意思。 您可能知道使用g ++编译器或GCC(GNU C编译器)也许使用CC(Clang的编译器)或任何其他编译器(也适用于其他语言),但这仅适用于一个源代码,如果您正在使用多个源代码且具有依赖性,并且每次文件更新时都需要更新,其他文件也需要更新,因此在这里很方便。

So what is make? It is a GNU utility to maintain groups of programs. Yes, you can use it on the terminal with the syntax:

那是什么? 它是一个GNU实用程序,用于维护程序组。 是的,您可以使用以下语法在终端上使用它:

    make  [option]... [target]...

什么牌子的? (What make does?)

This utility actually determines (automatically) which portion of the program need to recompile and issues the command to recompile them.

该实用程序实际上(自动)确定程序的哪一部分需要重新编译,并发出命令对其进行重新编译。

In this article, will discuss make's implementation using C language. Although make can be used for any other language whose compiler is compatible to run with a shell command. In fact, make can use to describe any task where some files need to update automatically from others whenever the others change.

在本文中,将讨论使用C语言进行make的实现 。 尽管make可以用于其编译器与shell命令兼容的任何其他语言。 实际上,make可以用来描述任何任务,其中只要其他文件发生更改,某些文件就需要自动从其他文件更新。

Let's have a small demonstration of make:

让我们来简单地演示一下make

Step 1: Create a C program [We created a simple program with name program1]

步骤1:创建一个C程序[我们创建了一个简单的程序,名称为program1]

Step 2: We follow command for make which is
make program1 (we used the name of the program without extension)

第2步:我们遵循make命令
make program1(我们使用的程序名称不带扩展名)

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

Now what will happen in this example is, make will look for program1 and when it doesn't found anywhere it will look source code with the same name. In our case, we had program1.c then make will check whether it can build from that source code that is whether necessary compilers are present or not. Now, we had C compiler and it runs the code and creates our object.

现在,在此示例中将发生的事情是,make将查找program1,并且在找不到的地方将查找具有相同名称的源代码。 在我们的例子中,我们有program1.c,然后make将检查它是否可以从该源代码进行构建,即是否存在必需的编译器。 现在,我们有了C编译器,它运行代码并创建我们的对象。

To prepare to make we need to create a file called makefile which maps the relationships among files in our program and also states the commands for updating each file. Usually, executables files are updated from object files and those object files are build by compiling the source code. After creating a makefile, each time we change some source files is sufficient for all required recompilations. The make program takes the makefile content and last modification times of the file and then decide which file For all those files which it will rebuild, it will issue the commands which are mentioned in the makefile. make execute commands present in the makefile (or sometimes can be named as Makefile). Targets are updated using make if it depends on a prerequisite files where some modification have been done since the target was last modified, or the target does not exist.

为了准备我们需要创建一个名为makefile文件,该文件的映射关系,在我们的程序文件中,也指出了命令用于更新每个文件。 通常,可执行文件是从目标文件更新的,而这些目标文件是通过编译源代码来构建的。 创建makefile后,每次更改一些源文件就足以进行所有必需的重新编译。 make程序获取makefile的内容和文件的最后修改时间,然后确定哪个文件对于将要重建的所有那些文件,它将发出makefile中提到的命令。 make执行命令(存在于makefile中)(有时可以称为Makefile)。 如果目标依赖于自上次修改目标以来已经进行了一些修改的前提文件,或者目标不存在,则使用make更新目标。

Examples:

例子:

    make

Now we will understand makefile, but before that, we need to make utility in our machine, usually make come pre-installed but in case we don't have we can download it by:

现在我们将了解makefile,但在此之前,我们需要在计算机中制作实用程序,通常会预先安装make,但是如果没有,我们可以通过以下方式下载它:

    sudo apt install build-essential

After installing make utility, to make sure that properly installed it in our machine we check the version of its version installed:

安装make实用程序后,为确保在我们的计算机中正确安装了该实用程序,请检查已安装版本的版本:

    make --version

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

Time to create our makefile, so what do is we create a file with any text editor (vi, vim or nano) to create a file name makefile (or Makefile, both will work).

是时候创建我们的makefile了,所以我们要做的是使用任何文本编辑器(vi,vim或nano)创建一个文件,以创建文件名makefile(或Makefile,都可以使用)。

We created our makefile:

我们创建了我们的makefile:

Now we will try all three options we made.

现在,我们将尝试使用所有三个选项。

First, we run make with clean and then demo.

首先,我们先运行make,然后进行演示。

You can notice the pattern that first it prints the command it is going to run then execute it.

您会注意到一种模式,它首先打印将要运行的命令,然后执行它。

Now we see the make all:

现在我们看到了全部:

Did you notice something?

你有注意到吗?

Yes, it produced an error as program1 doesn't exist ( we cleaned it in above using clean option). Once a command executiongives fault it stop make execution. So we create the program1 and call make all command and this time we get success.

是的,由于program1不存在,它产生了一个错误(我们在上面使用clean选项清除了它)。 一旦命令执行出现故障,它将停止执行。 因此,我们创建了program1并调用make all命令,这一次我们获得了成功。

Tips:

提示:

  1. command: make

    命令 : make

  2. is equivalent to : make all

    等效于 : 全部

While creating makefile use tabs for spacing don't mix tabs and spaces.

创建makefile时,请使用制表符分隔空格,请勿混用制表符和空格。

Recommended Articles:

推荐文章:

  • Compression techniques in Linux

    Linux中的压缩技术

  • Archiving Files Using Linux Command Line

    使用Linux命令行归档文件

  • ZIP files on command line in Linux

    Linux中命令行上的ZIP文件

翻译自: https://www.includehelp.com/linux/make-utility-makefile.aspx

在Linux中制作实用程序(MakeFile)相关推荐

  1. linux字符界面播放vcd,在Linux中制作VCD

    在Linux中制作VCD 发布时间:2006-03-25 01:04:08来源:红联作者:zz123 ---- 也许您还在使用Windows的原因之一是Windows强大的多媒体支持能力,例如制作个性 ...

  2. 在linux中制作IOS文件

    1.从光盘中制作ISO文件: 把光盘放入光驱中(注意不需要挂载光盘) 格式:cp  /dev/cdrom  ISO文件名 执行下列命令: #cp  /dev/cdrom  mycd.iso 可以使用f ...

  3. bazel 链接第三方动态库_C语言学习篇(31)——linux中制作动态链接库

    引言 前面我们讲解了什么是函数库(函数库就是一些事先写好的函数集合),函数库有什么作用(可以打包我们的编写的源代码,供他人使用,同时源码不可见,保护了自己的知识产权)以及函数库有2种提供方式:静态链接 ...

  4. 在linux下vcd光盘提取,在Linux中制作VCD

    -- 也许您还在使用Windows的原因之一是Windows强大的多媒体支持能力,例如制作个性十足的VCD光盘.的确如此, Windows操作系统到目前为止仍然拥有操作系统中最强大的多媒体能力,因为有 ...

  5. Linux中制作本地yum源

    第一步:挂载镜像驱动 第二步:备份原始yum仓库 1.进入yum.repos.d目录      cd /etc/yum.repos.d 2.备份原始的yum仓库文件,创建一个old目录,把原始的yum ...

  6. 在Linux中制作Windows10启动U盘

    需要准备: win10镜像.WoeUSB 操作步骤:git clone https://github.com/slacka/WoeUSB.git #下载WoeUSBcd WoeUSB/./setup- ...

  7. Linux 中创建 USB 启动盘来拯救 Windows 用户

    WoeUSB 可以在 Linux 中制作 Windows 启动盘,并帮助你的朋友解锁他们罢工的机器. 人们经常要求我帮助他们恢复被锁死或损坏的 Windows 电脑.有时,我可以使用 Linux US ...

  8. linux xargs命令_如何在Linux中使用xargs命令?

    linux xargs命令 The xargs command allows us to pass the output of one command as the input for another ...

  9. linux下制作win7安装U盘

    http://blog.csdn.net/pipisorry/article/details/41369821 已装linux,再用U盘安装win7(网络安装应该也可以), 先要在linux里面制作一 ...

最新文章

  1. 切换阿里云maven源解决maven中央仓库下载太慢卡顿的问题
  2. php编码 js解码,浅谈php和js中json的编码和解码
  3. php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳
  4. iOS6和iOS7代码的适配(1)
  5. 计算机科学个人陈述,计算机专业个人陈述样本
  6. [Python图像处理] 三十七.OpenCV直方图统计两万字详解(掩膜直方图、灰度直方图对比、黑夜白天预测)
  7. 磁盘与目录的容量(转)
  8. MacBook/MacOS/Mac OS 查看进程/端口信息的相关命令
  9. oracle sql去差集,Oracle 两个逗号分割的字符串,获取交集、差集的sql实现过程解析...
  10. Java程序设计基础笔记 • 【第1章 初识Java】
  11. 海康摄像头不记得登陆密码了怎么办?2020年联系人工客服最新版解答方案
  12. win10录屏_win10录屏打不开怎么办?怎么给win10录制屏幕视频?
  13. MATLAB dir函数文件名排序问题
  14. 用青龙跑渤海宣传员(收益很稳定)
  15. deepfake ai智能换脸_AI换脸之后,智能去除马赛克视频工具被疯传,测试结果令人意外...
  16. Win11图标变暗怎么办?Win11图标变暗的解决方法
  17. 声网首席科学家钟声:感知实时互联网
  18. 【JAVA】学习java 基础知识
  19. 菜刀如何连接mysql_中国菜刀之终端操作及数据库管理
  20. 食品工程原理之流体动力学

热门文章

  1. AOE网的关键路径的计算
  2. arm linux 中断优先级,ARM中断处理过程
  3. python实现队列_Python学习教程:用队列实现栈
  4. kali里PHP文件502错误,解决Linux Kali iptables开放22端口失败等一系列问题
  5. 分页请求json数据_Python爬虫入门教程 28-100 虎嗅网文章数据抓取 pyspider
  6. timm 视觉库中的 create_model 函数详解
  7. java文件编码格式环境变量_Jenkins maven 构建乱码,修改file.encoding系统变量编码为UTF-8...
  8. oracle的exp和imp,oracle exp和imp
  9. atomikosdatasourcebean mysql_SpringBoot2整合JTA组件实现多数据源事务管理
  10. centos常用命令_二、Docker镜像是什么?Docker常用命令