日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

初识makefile

發布時間:2025/4/14 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 初识makefile 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
make是常用的一個管理工程編譯的工具
其基本用法是:
1、make,使用makefile作為規則文件
2、make -f mf,使用mf作為makefile
3、make all,make clean 指定目標
4、make CPP=g++ 宏定義替換

make的重點在makefile的內容

0、基本格式

# comment target: dependencyrule若target時間比dependency早,則根據rule生成target
注:rule前面是tab,不是空格

1、簡單的makefile

hello.exe: hello.cppg++ -o hello.exe hello.cpp?2、宏 macro
使用宏可以方便替換不同的工具

CPP = g++ hello.exe: hello.cpp$(CPP) -o hello.exe hello.cpp這里CPP 就是一個宏定義,make會根據規則把它替換為g++
make自己定義了若干內部宏,常見的有:
$?:比目標的修改時間更晚的那些依賴模塊表
$@:當前目標的全路徑名。可用于用戶定義的目標名的相關行中
$<:比給定的目標文件時間標記更新的依賴文件名
$*:去掉后綴的當前目標名。例如,若當前目標是pro.o,則$*表示pro

?? ?
3、后綴規則 suffix rule
可以使用后綴規則,縮短時間
.SUFFIXES: .exe .cpp .cpp.exe: # make exe from cppg++ -o $@ $< hello.exe: hello.cpp

4、默認目標 default target
經常看見make,后面什么也沒有指定,說明使用了默認目標
第一個目標就是默認目標

all:\hello.exe\test.exe hello.exe: hello.cppg++ -o hello.exe hello.cpp test.exe: test.cgcc -o test.exe test.c
5、一個完整的例子
# 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

轉載于:https://www.cnblogs.com/xkxjy/p/3672252.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的初识makefile的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。