当前位置:网站首页>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 test
makefile2:
#“:”代表依赖,另外每个处理动作之前都要用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
边栏推荐
- float与0比较
- 为什么线程崩溃不会导致 JVM 崩溃
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
- Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
- leetcode:动态规划模板
- QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
- File rename
- MongoDB简介
- The calculation of stripe, kernel and padding in CNN
- About HTTP cache control
猜你喜欢
MySQL practice 45 lecture [row lock]
Mongodb installation & Deployment
渤、黄海的潮汐特征
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
Lvgl usage experience
VS 2019 配置tensorRT生成engine
FileZilla Client下载安装
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
Mysql Mac版下载安装教程
随机推荐
ffmpeg下载安装教程及介绍
解决高並發下System.currentTimeMillis卡頓
Pytorch配置
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
MongoDB簡介
900W+ 数据,从 17s 到 300ms,如何操作
FileZilla Client下载安装
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Change and access of median value of listening object
Yolov5 project based on QT
基于Qt的yolov5工程
MongoDB基本操作【增、删、改、查】
MySQL MAC download and installation tutorial
PHP generates PDF tcpdf
PAT乙级“1104 天长地久”DFS优化思路
Table structure of Navicat export database
Vs 2019 configuration tensorrt
【PyG】理解MessagePassing过程,GCN demo详解
The series of hyperbolic function in daily problem