当前位置:网站首页>Makefile demo
Makefile demo
2022-07-03 03:39:00 【___ Bozi mi pro】
make Tools are a basis makefile The contents of the document , Target ( Executable file ) Perform dependency detection ( What intermediate files are required before generating the executable ) And perform the relevant actions ( Compile etc. ) Tools for . And this makefile The file is similar to a script , The content includes make Processing actions to be performed and dependencies .
makefile The main content to be carried out is to clarify the goal 、 Clarify what the goal depends on 、 Specify that the corresponding processing actions should be performed when the dependency conditions are met . For example, we will finally realize a This goal , But you have to rely on b, and b Depend on c The existence of , Can be described as :
a:b
cmdbtoa
b:c
cmdctob
“:” On behalf of dependence , In addition, you should use before each processing action tab The key to separate . The four lines above mean :a Depend on b, And deal with cmdbtoa;b Depend on c, And deal with cmdctob.
gcc Yes C/C++ Compilation process , It is divided into four parts , Preprocessing , compile , assembly , link .

makefile1:
C = gcc
G = g++
CFLAGS = -Wall -O -g
TARGET = ./test
# Means to put all .c、.cpp File compiled into .o file .
# $ @ Expand to the destination file name of the current rule
# $ < Expand to the first dependency file in the dependency list
# $^ Expand to the entire list of dependencies ( Get rid of all duplicate file names ).
%.o:%.c
$(C) $(CFLAGS) -c $< -o [email protected]
%.o:%.cpp
$(G) $(CFLAGS) -c $< -o [email protected]
# Means to generate an all with .c、.cpp List of files at the end , Then store the variable SOURCES in .
SOURCES = $(wildcard *.c *.cpp)
# hold SOURCES All files in the file list .cpp become .o、.c become .o, Then form a new list , Deposit in OBJS Variable .
OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
$(TARGET):$(OBJS)
$(G) $(OBJS) -o $(TARGET)
#chmod a+x $(TARGET) Express the firstTest Force into executable
chmod a+x $(TARGET)
clean:
rm -rf *.o testmakefile2:
#“:” On behalf of dependence , In addition, you should use before each processing action tab The key to separate .
OBJS = test1.o test2.o
G = gcc
# CFLAGS = -Wall -O -g Configure compiler settings , And assign it to CFLAGS Variable
# -Wall: Output all warning messages
# -O: Optimize at compile time
# -g: Represents compilation debug edition
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边栏推荐
- 动态规划:最长公共子串和最长公共子序列
- shardingsphere动态数据源
- Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
- C语言HashTable/HashSet库汇总
- C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
- 监听对象中值变化及访问
- Convert binary stream to byte array
- umi 路由拦截(简单粗暴)
- [leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
- Mongodb master profile
猜你喜欢

docker安装及启动mysql服务

MongoDB安装 & 部署

Ffmpeg download and installation tutorial and introduction

Pat class B "1104 forever" DFS optimization idea

Limit of one question per day

Message queue addition failure

Téléchargement et installation du client Filezilla

Docker install and start MySQL service

Hi3536c v100r001c02spc040 cross compiler installation

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
随机推荐
Unity3d RPG implementation (medium)
VS克隆时显示403错误
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
FileZilla Client下载安装
For instruction, uploading pictures and display effect optimization of simple wechat applet development
【DRM】DRM bridge驱动调用流程简单分析
Makefile demo
leetcode:动态规划模板
900w+ data, from 17s to 300ms, how to operate
Pat class B "1104 forever" DFS optimization idea
FileZilla Client下載安裝
Shardingsphere dynamic data source
Limit of one question per day
递归使用和多维数组对象变一维数组对象
Yolov5 project based on QT
403 error displayed when vs cloning
[combinatorics] basic counting principle (addition principle | multiplication principle)
机械臂速成小指南(八):运动学建模(标准DH法)
如何迈向IPv6之IPv6过渡技术-尚文网络奎哥