当前位置:网站首页>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 test
makefile2:
#“:” 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
边栏推荐
- Captura下载安装及在Captura配置FFmpeg
- Bigvision code
- 监听对象中值变化及访问
- Web会话管理安全问题
- NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr
- The calculation of stripe, kernel and padding in CNN
- MongoDB主配置文件
- 递归:深度优先搜索
- Stepping on pits and solutions when using inputfilter to limit EditText
- Download and install node, NPM and yarn
猜你喜欢
随机推荐
Limit of one question per day
MongoDB簡介
PHP generates PDF tcpdf
[MySQL] the difference between left join, right join and join
[pyg] understand the messagepassing process, GCN demo details
Application of derivative in daily question
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
渤、黄海的潮汐特征
[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
【学习笔记】seckill-秒杀项目--(11)项目总结
Recursive use and multi-dimensional array object to one-dimensional array object
[combinatorics] basic counting principle (addition principle | multiplication principle)
Summary of electromagnetic spectrum
C # webrequest post mode, based on "basic auth" password authentication mode, uploads files and submits other data using multipart / form data mode
Dynamic programming: longest common substring and longest common subsequence
IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network
Pytoch configuration
Limit of one question per day
Convert binary stream to byte array
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!