日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c++17(28)-Makefile(1)

發布時間:2025/3/12 c/c++ 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++17(28)-Makefile(1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、make尋找Makefile并按里面的編排進行編譯
2、前方空格實質不是空格,而是tab

(base) [myhaspl@localhost learncpp2]$ make g++ main.cpp -o test (base) [myhaspl@localhost learncpp2]$ ls main.cpp Makefile test (base) [myhaspl@localhost learncpp2]$ ./test func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$ cat Makefile CPP=g++ test:main.cpp${CPP} main.cpp -o test (base) [myhaspl@localhost learncpp2]$ cat main.cpp #include <iostream> using namespace std;void func1(){cout<<"func1"<<endl; } void func2(){cout<<"func2"<<endl; } void func3(){cout<<"func3"<<endl; } int func4(int x){cout<<x<<endl;return x+6; }int main(int argc, char **argv) {void (*f1)(){func1};(*f1)();//函數指針void (*f[])(){func2,func3};//函數數組指針(*f[0])();(*f[1])();int (*f4)(int){func4}; //函數指針 cout<<(*f4)(22)<<endl;} (base) [myhaspl@localhost learncpp2]$ make g++ main.cpp (base) [myhaspl@localhost learncpp2]$ make test g++ main.cpp (base) [myhaspl@localhost learncpp2]$ CPP = g++ test:main.cpp$(CPP) main.cpp

下面一步步擴展:
(1)

CPP = g++ test:main.o$(CPP) main.o -o test main.o:main.cpp$(CPP) -c main.cpp -o main.o (base) [myhaspl@localhost learncpp2]$ make test g++ main.o -o test (base) [myhaspl@localhost learncpp2]$ ls a.out main main.cpp main.o Makefile test (base) [myhaspl@localhost learncpp2]$ ./test func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$ (base) [myhaspl@localhost learncpp2]$ rm test (base) [myhaspl@localhost learncpp2]$ make g++ main.o -o test (base) [myhaspl@localhost learncpp2]$ ls a.out main main.cpp main.o Makefile test (base) [myhaspl@localhost learncpp2]$ ./test func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$

(2)

CPP = g++ test:main.o$(CPP) main.o -o test main.o:main.cpp$(CPP) -c main.cpp -o main.o clean:rm -f test (base) [myhaspl@localhost learncpp2]$ make clean rm -f test (base) [myhaspl@localhost learncpp2]$ make g++ main.o -o test

(3)

CPP = g++ CPPFILES=main.cpp test:main.o$(CPP) main.o -o test main.o:$(CPPFILES)$(CPP) -c main.cpp -o main.o clean:rm -f test CPP = g++ main:main.o$(CPP) -o main main.o

(4)

CPP = g++ CPPFILES=main.cpp OFILES=main.o test:$(OFILES)$(CPP) $(OFILES) -o test main.o:$(CPPFILES)$(CPP) -c $(CPPFILES) -o $(OFILES) clean:rm -f test

(5)

CPP = g++ CPPFILES=main.cpp OFILES=main.o test:$(OFILES)$(CPP) $(OFILES) -o test main.o:$(CPPFILES)$(CPP) -c $(CPPFILES) -o $(OFILES) clean:rm -f test $(OFILES) (base) [myhaspl@localhost learncpp2]$ make clean rm -f test main.o (base) [myhaspl@localhost learncpp2]$ make g++ -c main.cpp -o main.o g++ main.o -o test (base) [myhaspl@localhost learncpp2]$ ./test func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$

(6)

CPP = g++ CPPFILES=main.cpp OFILES=main.o all:test test:$(OFILES)$(CPP) $(OFILES) -o test main.o:$(CPPFILES)$(CPP) -c $(CPPFILES) -o $(OFILES) clean:rm -f test $(OFILES)

(7)

CPP = g++ all:test1 test2 test1:main1.o$(CPP) main1.o -o test1 test2:main2.o$(CPP) main2.o -o test2 main1.o:main.cpp$(CPP) -c main.cpp -o main1.o main2.o:main2.cpp$(CPP) -c main2.cpp -o main2.o clean:rm -f test1 test2 main1.o main2.o (base) [myhaspl@localhost learncpp2]$ make clean rm -f test1 test2 main1.o main2.o (base) [myhaspl@localhost learncpp2]$ make g++ -c main.cpp -o main1.o g++ main1.o -o test1 g++ -c main2.cpp -o main2.o g++ main2.o -o test2 (base) [myhaspl@localhost learncpp2]$ ./test1 func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$ ./test2 hello (base) [myhaspl@localhost learncpp2]$ cat main2.cpp #include <iostream> using namespace std; int main(){cout<<"hello"<<endl; }(base) [myhaspl@localhost learncpp2]$

(8)

CPP = g++ all:test1 test2 oall oall:test1 test2# 輸出目標echo $@#輸出比目標還早的所有先決條件echo $?#輸出所有先決條件echo $^ test1:main1.o$(CPP) main1.o -o test1 test2:main2.o$(CPP) main2.o -o test2 main1.o:main.cpp$(CPP) -c main.cpp -o main1.o main2.o:main2.cpp$(CPP) -c main2.cpp -o main2.o clean:rm -f test1 test2 main1.o main2.o (base) [myhaspl@localhost learncpp2]$ make # 輸出目標 echo oall oall #輸出比目標還早的所有先決條件 echo test1 test2 test1 test2 #輸出所有先決條件 echo test1 test2 test1 test2 (base) [myhaspl@localhost learncpp2]$ ls a.out main1.cpp main1.o main2.cpp main2.o main.cpp Makefile test1 test2 (base) [myhaspl@localhost learncpp2]$ ./test1 func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$ ./test2 hello (base) [myhaspl@localhost learncpp2]$

(9)

(base) [myhaspl@localhost learncpp2]$ make clean rm -f test1 test2 test1.o test2.o main main.o (base) [myhaspl@localhost learncpp2]$ make g++ -c main.cpp -o main.o g++ main.o -o main g++ -c main.cpp -o test1.o g++ -c main2.cpp -o test2.o # 輸出目標 echo test test #輸出比目標還早的所有先決條件 echo test1.o test2.o test1.o test2.o #輸出所有先決條件 echo test1.o test2.o test1.o test2.o (base) [myhaspl@localhost learncpp2]$ CPP = g++ TEMPFILES=test1 test2 test1.o test2.o main main.o all:main test test:test1 test2# 輸出目標echo $@#輸出比目標還早的所有先決條件echo $?#輸出所有先決條件echo $^ test1:test1.o$(CPP) test1.o -o test1 test2:test2.o$(CPP) test2.o -o test2 test1.o:main1.cpp$(CPP) -c main1.cpp -o test1.o test2.o:main2.cpp$(CPP) -c main2.cpp -o test2.o main:main.o$(CPP) main.o -o main main.o:main.cpp$(CPP) -c main.cpp -o main.o clean:rm -f $(TEMPFILES)

(10)

CPP = g++ TEMPFILES=test1 test2 test1.o test2.o main main.o all:main test test:test1 test2# 輸出目標echo $@#輸出比目標還早的所有先決條件echo $?#輸出所有先決條件echo $^ test1:test1.o$(CPP) test1.o -o test1 test2:test2.o$(CPP) test2.o -o test2 test1.o:main1.cpp$(CPP) -c main1.cpp -o test1.o test2.o:main2.cpp$(CPP) -c main2.cpp -o test2.o main:main.o$(CPP) main.o -o main main.o:main.cpp$(CPP) -c main.cpp -o main.o clean:rm -f $(TEMPFILES) (base) [myhaspl@localhost learncpp2]$ make clean rm -f test1 test2 test1.o test2.o main main.o (base) [myhaspl@localhost learncpp2]$ make g++ -c main.cpp -o main.o g++ main.o -o main g++ -c main1.cpp -o test1.o g++ test1.o -o test1 g++ -c main2.cpp -o test2.o g++ test2.o -o test2 # 輸出目標 echo test test #輸出比目標還早的所有先決條件 echo test1 test2 test1 test2 #輸出所有先決條件 echo test1 test2 test1 test2 (base) [myhaspl@localhost learncpp2]$ ls a.out main1.cpp main2.cpp main.cpp Makefile test1.o test2.o main main1.o main2.o main.o test1 test2 (base) [myhaspl@localhost learncpp2]$ ./main func1 func2 func3 22 28 (base) [myhaspl@localhost learncpp2]$ ./test1 world (base) [myhaspl@localhost learncpp2]$ ./test2 hello

(11)

CPP = g++ TEMPFILES=test1 test2 test1.o test2.o main main.o all:main test test:test1 test2# 輸出目標echo $@#輸出比目標還早的所有先決條件echo $?#輸出所有先決條件echo $^ test1:test1.o$(CPP) $? -o $@ test2:test2.o$(CPP) $? -o $@ test1.o:main1.cpp$(CPP) -c $? -o $@ test2.o:main2.cpp$(CPP) -c $? -o $@ main:main.o$(CPP) $? -o $@ main.o:main.cpp$(CPP) -c $? -o $@ clean:rm -f $(TEMPFILES)

1、make的設計注重節約時間,只依賴于文件名字的后綴。
2、一條后綴規則是一種教make怎樣從一種類型文件(如:.cpp)轉化為另一種類型(如.obj和.exe)的方式。
3、一旦有了make從一種文件轉化為另外一種文件的規則,其他要做的只是告訴make哪些文件依賴于其他文件。
4、當make發現一個文件讓它依賴其他文件。
5、當make發現一個文件讓它依賴的文件舊,它就會使用用規則創建一個新文件。

CPP=g++ .SUFFIXES:.exe .cpp .cpp .exe${CPP} $<

1、.SUFFIXES指令指出:make要注意后面的擴展名,后綴規則.cpp和.exe,說明如何把.cpp轉化為.exe

總結

以上是生活随笔為你收集整理的c++17(28)-Makefile(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

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