当前位置:网站首页>The role of include in makefile
The role of include in makefile
2022-07-23 09:08:00 【Biao】
When we compile , I hope it has been changed c file , Just compile that one c file , meanwhile , When changing a header file , You also want to include this header file c Files are also compiled . For the former , It's simple ,make The default is to do this , And for the latter , But it needs our cooperation gcc Some options to achieve this . therefore include The function of is to improve the compilation speed .
( Of course not , We are makefile Write in xx.o:xx.c 1.h 2.h 3.h ... Can also be realized , Just tell make, My every .c Rely on all .h, This can also achieve any .h Revised , Will rewrite the compilation .o, But this obviously causes a lot of unnecessary compilation , The performance drops )
If you know now .c And those .h Our dependency , Store in a .d File can ( Obviously , How many .c, How many corresponding .d file ). then makefile Add a sentence to the list :
include xx.d
make Software is executing makefile Before the first goal in ( It's usually all The goal is ), Meeting Take this xx.d File included for use , can To guide the make The compilation process of the software , Reduce unnecessary compilation .
And how to know one c Which header files are included in the file Well ,make Software is unknown , Then what shall I do? , Compiler it knows ah , So let the compiler generate this dependency .d file . Compilers such as gcc by .c File generation .d file , Add an option ,gcc -MMD
But there is a problem here ,make For the first time makefile When ,.d The file doesn't exist yet , because gcc I haven't compiled it yet . At this time include xx.d It'll be wrong , such as :makefile:6: xxx.d: No such file or dirctory.
Of course, we can also give this xx.d Write a generation rule , such as :
xx.d:
@echo "-------- [email protected] ---------"
In this case , Will be the default in makefile In order to find xxx.d Target rules and execute , If the rule is not found , An error will be reported and the execution will be suspended .make: *** No rule to make target `tmp.d'. Stop.
therefore make Handle include tmp.d When , The execution process is as follows :
1. Check makefile Whether there is tmp.d file , If you find , End and apply tmp.d file , Otherwise, a warning will be given .
2. lookup makefile Is there any in the document with tmp.d Rules for the goal , If you find , End and apply tmp.d file , Otherwise, an error will be reported .
Because of our xx.d Files depend on compiler generated , So for the first time make, This file is not available , So it will report a mistake , And don't write tmp.d Target rules , And directly make Execution stop . We just need to write as
-include xx.d, So that we can Give Way make Don't make a mistake , You can continue to run . First compilation , It doesn't matter if you don't rely on files , Because it will be all anyway .c All need to be compiled , Well .
although make Each time, it is generated by the last compilation .d file , But it doesn't matter , Because a .c Rely on the .h The file has changed , It will be recompiled , And this .c This header file is not included , Belong to .c The contents of the document have changed , It will be recompiled , therefore , This dependency is generated by the last compilation .d file , Is safe , Correct .
Reference article :
Makefile in include Have to use _qq_542865340 The blog of -CSDN Blog _makefile add to include
边栏推荐
- There was an accident caused by MySQL misoperation, and "high availability" couldn't stand it
- DALSA smart camera boa spot communicates with Siemens s7-1200 PROFINET
- 工作中遇到一个bug的解决过程
- In depth explanation of CAS is necessary for interview practice
- PMP一手资料、一手资讯获取
- 【管理篇 / 升级】* 02. 查看升级路径 * FortiGate 防火墙
- 198. 打家劫舍
- SQL用户表的通用设计
- disruptor框架无锁实现生产者消费者代码实例
- Unity中实现判断Missing还是Null
猜你喜欢

-Bash: wget: command not found

UGUI源码解析——Mask

正则表达式转换为相应的文字小工具
![[ctfshow web getting started]ssrf](/img/eb/19c215fcacc0f101510a77c6d1edc3.png)
[ctfshow web getting started]ssrf

吉利星瑞:从产品技术赋能到文化自信

【云原生】风云暗涌的时代,DBA们的利刃出鞘了

PMP一手资料、一手资讯获取

解析创客教育活动所需的空间实践场

Mathematical modeling -- graph and network models and methods (II)

The most detailed explanation of the output of three numbers from large to small
随机推荐
BGP联邦实验
SQL Server database design -- select statement
DOM系列之禁止选中文字和禁止右键菜单
砥砺前行新征程,城链科技狂欢庆典在厦门隆重举行
全新 IDEA 2022.2 正式发布,新特性很NICE
Found a useful data analysis tool
Is it safe to open an account online? How about Galaxy Securities
讲一讲HART协议
NodeJS 基于 Dapr 构建云原生微服务应用,从 0 到 1 快速上手指南
The most detailed explanation of the output of three numbers from large to small
Practical exercise | a simple method for MySQL processlist table and Navicat monitor to identify slow queries
NodeJS 基于 Dapr 构建云原生微服务应用,从 0 到 1 快速上手指南
Svg+js mouse hover parallax JS effect
启牛开户安全性高吗?说万3的佣金靠谱吗?
股票开户网上开户安全吗,银河证券怎么样
Canal realizes MySQL data synchronization
The concept and method of white box test
Trigger event when input is completed
Internet Download Manager简直就是下载器中的大杀器
视频点播中相关分辨率说明