c++17(28)-Makefile(1)
生活随笔
收集整理的這篇文章主要介紹了
c++17(28)-Makefile(1)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、make尋找Makefile并按里面的編排進行編譯
2、前方空格實質不是空格,而是tab
下面一步步擴展:
(1)
(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發現一個文件讓它依賴的文件舊,它就會使用用規則創建一個新文件。
1、.SUFFIXES指令指出:make要注意后面的擴展名,后綴規則.cpp和.exe,說明如何把.cpp轉化為.exe
總結
以上是生活随笔為你收集整理的c++17(28)-Makefile(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员法律考试笔记(1)-民法基本规定与
- 下一篇: springboot接收get和post