当前位置:网站首页>Makefile demo
Makefile demo
2022-07-03 03:28:00 【___波子MI Pro.】
make工具是一个根据makefile文件内容,针对目标(可执行文件)进行依赖性检测(要生成该可执行文件之前要有哪些中间文件)并执行相关动作(编译等)的工具 。而这个makefile文件类似一个脚本,其中内容包含make所要进行的处理动作以及依赖关系。
makefile所要进行的主要内容是明确目标、明确目标所依赖的内容、明确依赖条件满足时应该执行对应的处理动作。例如我们最终要实现a这个目标,但是需要依赖b,而b依赖于c的存在,则可以描述为:
a:b
cmdbtoa
b:c
cmdctob
“:”代表依赖,另外每个处理动作之前都要用tab键分隔。上述四行的意思是:a依赖于b,而处理cmdbtoa;b依赖于c,而处理cmdctob。
gcc对C/C++的编译过程,共分为四部分,预处理,编译,汇编,链接。

makefile1:
C = gcc
G = g++
CFLAGS = -Wall -O -g
TARGET = ./test
#表示把所有的.c、.cpp文件编译成.o文件。
# $ @扩展成当前规则的目的文件名
# $ <扩展成依靠列表中的第一个依靠文件
# $^扩展成整个依靠的列表(除掉里面所有重复的文件名)。
%.o:%.c
$(C) $(CFLAGS) -c $< -o [email protected]
%.o:%.cpp
$(G) $(CFLAGS) -c $< -o [email protected]
#表示产生一个所有以.c、.cpp结尾的文件列表,然后存入变量SOURCES里。
SOURCES = $(wildcard *.c *.cpp)
#把SOURCES文件列表中所有.cpp变成.o、.c变成.o,然后形成一个新的列表,存入OBJS变量。
OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
$(TARGET):$(OBJS)
$(G) $(OBJS) -o $(TARGET)
#chmod a+x $(TARGET) 表示把firstTest强制变成可执行文件
chmod a+x $(TARGET)
clean:
rm -rf *.o testmakefile2:
#“:”代表依赖,另外每个处理动作之前都要用tab键分隔。
OBJS = test1.o test2.o
G = gcc
# CFLAGS = -Wall -O -g 配置编译器设置,并把它赋值给CFLAGS变量
# -Wall:输出所有警告信息
# -O:在编译时进行优化
# -g:表示编译debug版本
CFLAGS = -Wall -O -g
test:$(OBJS)
$(G) $(OBJS) -o test
test1.o:test1.c test2.h
$(G) $(CFLAGS) -c test1.c
test2.o:test2.c test2.h
$(G) $(CFLAGS) -c test2.c
clean:
rm -rf *.o test边栏推荐
- [algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
- Table structure of Navicat export database
- Download and install node, NPM and yarn
- 二进制流转换成字节数组
- [combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
- Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
- VS code配置虚拟环境
- 别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
- [combinatorics] basic counting principle (addition principle | multiplication principle)
- Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
猜你喜欢

QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序

Téléchargement et installation du client Filezilla

Limit of one question per day

PHP generates PDF tcpdf

900W+ 数据,从 17s 到 300ms,如何操作

Spark on yarn resource optimization ideas notes

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled

MySQL MAC download and installation tutorial

VS code配置虚拟环境
随机推荐
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
Ansible introduction [unfinished (semi-finished products)]
About HTTP cache control
机械臂速成小指南(八):运动学建模(标准DH法)
MongoDB安装 & 部署
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
【PyG】理解MessagePassing过程,GCN demo详解
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
Pytoch lightweight visualization tool wandb (local)
Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
docker安装及启动mysql服务
Basic operations of mongodb [add, delete, modify, query]
Use of El tree search method
[MySQL] the difference between left join, right join and join
Nce detail of softmax approximation
解决高并发下System.currentTimeMillis卡顿
Réglez la hauteur et lancez le système. Currenttimemillis catton
使用InputFilter限制EditText时踩坑及解决方案
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop