当前位置:网站首页>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
边栏推荐
- MongoDB简介
- QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
- Download and install node, NPM and yarn
- MongoDB复制集【主从复制】
- Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
- Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
- [mathematical logic] normal form (conjunctive normal form | disjunctive normal form | major item | minor item | maximal item | minor item | principal conjunctive normal form | principal disjunctive no
- MongoDB基本操作【增、删、改、查】
- [combinatorics] basic counting principle (addition principle | multiplication principle)
- 监听对象中值变化及访问
猜你喜欢
MongoDB简介
Nce detail of softmax approximation
ffmpeg录制屏幕和截屏
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
Some preliminary preparations for QQ applet development: make an appointment for a development account, download and install developer tools, and create QQ applet
Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
On the adjacency matrix and adjacency table of graph storage
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
[MySQL] the difference between left join, right join and join
Idea set method call ignore case
随机推荐
Download and install node, NPM and yarn
900w+ data, from 17s to 300ms, how to operate
VS克隆时显示403错误
[combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
MySQL MAC download and installation tutorial
Basic operations of mongodb [add, delete, modify, query]
Yolov5 project based on QT
Change and access of median value of listening object
Pytorch配置
softmax的近似之NCE详解
PHP constructor with parameters - PHP constructor with a parameter
Vs 2019 configuration du moteur de génération de tensorrt
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
Use three JS make a simple 3D scene
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
基于Qt的yolov5工程
Stepping on pits and solutions when using inputfilter to limit EditText
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
Introduction to mongodb
Converts a timestamp to a time in the specified format