初识makefile
生活随笔
收集整理的這篇文章主要介紹了
初识makefile
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
make是常用的一個(gè)管理工程編譯的工具
其基本用法是:
1、make,使用makefile作為規(guī)則文件
2、make -f mf,使用mf作為makefile
3、make all,make clean 指定目標(biāo)
4、make CPP=g++ 宏定義替換
make的重點(diǎn)在makefile的內(nèi)容
注:rule前面是tab,不是空格
使用宏可以方便替換不同的工具
CPP = g++ hello.exe: hello.cpp$(CPP) -o hello.exe hello.cpp這里CPP 就是一個(gè)宏定義,make會(huì)根據(jù)規(guī)則把它替換為g++
make自己定義了若干內(nèi)部宏,常見的有:
$?:比目標(biāo)的修改時(shí)間更晚的那些依賴模塊表
$@:當(dāng)前目標(biāo)的全路徑名。可用于用戶定義的目標(biāo)名的相關(guān)行中
$<:比給定的目標(biāo)文件時(shí)間標(biāo)記更新的依賴文件名
$*:去掉后綴的當(dāng)前目標(biāo)名。例如,若當(dāng)前目標(biāo)是pro.o,則$*表示pro
?? ?
3、后綴規(guī)則 suffix rule
可以使用后綴規(guī)則,縮短時(shí)間
.SUFFIXES: .exe .cpp .cpp.exe: # make exe from cppg++ -o $@ $< hello.exe: hello.cpp
5、一個(gè)完整的例子
# complete example CPP = g++ CC = gcc OFLAG = -o .SUFFIXES: .exe .cpp .c .obj .cpp.exe:$(CPP) $(OFLAG) $@ $< .obj.exe:$(CC) $(OFLAG) $@ $< .c.obj:$(CC) $(OFLAG) $@ -c $<all:\hello.exe\test.exe hello.exe: hello.cpp test.exe: test.obj test.obj: test.cclean:del *.exedel *.obj
參考:
1、TICPP_VOL1_chapter3
2、http://blog.csdn.net/it_yuan/article/details/8649407
其基本用法是:
1、make,使用makefile作為規(guī)則文件
2、make -f mf,使用mf作為makefile
3、make all,make clean 指定目標(biāo)
4、make CPP=g++ 宏定義替換
make的重點(diǎn)在makefile的內(nèi)容
0、基本格式
# comment target: dependencyrule若target時(shí)間比dependency早,則根據(jù)rule生成target注:rule前面是tab,不是空格
1、簡(jiǎn)單的makefile
使用宏可以方便替換不同的工具
CPP = g++ hello.exe: hello.cpp$(CPP) -o hello.exe hello.cpp這里CPP 就是一個(gè)宏定義,make會(huì)根據(jù)規(guī)則把它替換為g++
make自己定義了若干內(nèi)部宏,常見的有:
$?:比目標(biāo)的修改時(shí)間更晚的那些依賴模塊表
$@:當(dāng)前目標(biāo)的全路徑名。可用于用戶定義的目標(biāo)名的相關(guān)行中
$<:比給定的目標(biāo)文件時(shí)間標(biāo)記更新的依賴文件名
$*:去掉后綴的當(dāng)前目標(biāo)名。例如,若當(dāng)前目標(biāo)是pro.o,則$*表示pro
?? ?
3、后綴規(guī)則 suffix rule
可以使用后綴規(guī)則,縮短時(shí)間
.SUFFIXES: .exe .cpp .cpp.exe: # make exe from cppg++ -o $@ $< hello.exe: hello.cpp
4、默認(rèn)目標(biāo) default target
經(jīng)常看見make,后面什么也沒有指定,說明使用了默認(rèn)目標(biāo)
第一個(gè)目標(biāo)就是默認(rèn)目標(biāo)
5、一個(gè)完整的例子
# complete example CPP = g++ CC = gcc OFLAG = -o .SUFFIXES: .exe .cpp .c .obj .cpp.exe:$(CPP) $(OFLAG) $@ $< .obj.exe:$(CC) $(OFLAG) $@ $< .c.obj:$(CC) $(OFLAG) $@ -c $<all:\hello.exe\test.exe hello.exe: hello.cpp test.exe: test.obj test.obj: test.cclean:del *.exedel *.obj
參考:
1、TICPP_VOL1_chapter3
2、http://blog.csdn.net/it_yuan/article/details/8649407
轉(zhuǎn)載于:https://www.cnblogs.com/xkxjy/p/3672252.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的初识makefile的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。