Ubuntu之make:make命令行工具的简介、安装、使用方法之详细攻略
Ubuntu之make:make命令行工具的簡介、安裝、使用方法之詳細攻略
?
?
目錄
make命令行工具的簡介
make命令行工具的安裝
make命令行工具的使用方法
?
?
make命令行工具的簡介
? ? ?Ubuntu Make is a command line tool which allows you to download the latest version of popular developer tools on your installation, installing it alongside all of the required dependencies (which will only ask for root access if you don't have all the required dependencies installed already), enable multi-arch on your system if you are on a 64 bit machine, integrate it with the Unity launcher. Basically, one command to get your system ready to develop with!
? ? ? Ubuntu Make是一個命令行工具,允許您在安裝時下載最新版本的流行開發(fā)人員工具,并將其與所有必需的依賴項一起安裝(如果尚未安裝所有必需的依賴項,則只要求根訪問),啟用e如果您在64位機器上,系統(tǒng)上的multi-arch與Unity啟動器集成。基本上,一個命令可以讓您的系統(tǒng)準備好進行開發(fā)!
? ? ? ?無論是在Linux還是在Unix環(huán)境中,make都是一個非常重要的編譯命令。不管是自己進行項目開發(fā)還是安裝應用軟件,我們都經(jīng)常要用到make或make install。利用make工具,我們可以將大型的開發(fā)項目分解成為多個更易于管理的模塊,對于一個包括幾百個源文件的應用程序,使用make和makefile工具就可以簡潔明快地理順各個源文件之間紛繁復雜的相互關系。而且如此多的源文件,如果每次都要鍵入gcc命令進行編譯的話,那對程序員來說簡直就是一場災難。而make工具則可自動完成編譯工作,并且可以只對程序員在上次編譯后修改過的部分進行編譯。因此,有效的利用make和makefile工具可以大大提高項目開發(fā)的效率。同時掌握make和makefile之后,您也不會再面對著Linux下的應用軟件手足無措了。
ubuntu-makewiki
?
make命令行工具的安裝
先更新找到ubuntu-make,再下載
sudo apt-get update
sudo apt-get install ubuntu-make
190727更新
sudo apt-get install make
?
?
make命令行工具的使用方法
1、Make命令參數(shù)的典型序列如下所示
make [-f makefile文件名][選項][宏定義][目標]? ? ?#這里用[]括起來的表示是可選的。命令行選項由破折號“–”指明,后面跟選項
2、?一個簡單的例子
為了編譯整個工程,你可以簡單的使用 make 或者在 make 命令后帶上目標 all。
$ make gcc -c -Wall test.c gcc -c -Wall anotherTest.c gcc -Wall test.o anotherTest.o -o test你能看到 make 命令第一次創(chuàng)建的依賴以及實際的目標。
如果你再次查看目錄內(nèi)容,里面多了一些 .o 文件和執(zhí)行文件:
$ ls anotherTest.c anotherTest.o Makefile test test.c test.h test.o現(xiàn)在,假設你對 test.c 文件做了一些修改,重新使用 make 編譯工程:
$ make gcc -c -Wall test.c gcc -Wall test.o anotherTest.o -o test你可以看到只有 test.o 重新編譯了,然而另一個 Test.o 沒有重新編譯。
現(xiàn)在清理所有的目標文件和可執(zhí)行文件 test,你可以使用目標 clean:
$ make clean rm -rf *.o test $ ls anotherTest.c Makefile test.c test.h你可以看到所有的 .o 文件和執(zhí)行文件 test 都被刪除了。
?
3. 通過 -B 選項讓所有目標總是重新建立
到目前為止,你可能注意到 make 命令不會編譯那些自從上次編譯之后就沒有更改的文件,但是,如果你想覆蓋 make 這種默認的行為,你可以使用 -B 選項。下面是個例子:
$ make make: Nothing to be done for `all'.$ make -B gcc -c -Wall test.c gcc -c -Wall anotherTest.c gcc -Wall test.o anotherTest.o -o test你可以看到盡管 make 命令不會編譯任何文件,然而 make -B 會強制編譯所有的目標文件以及最終的執(zhí)行文件。
3. 使用 -d 選項打印調(diào)試信息
如果你想知道 make 執(zhí)行時實際做了什么,使用 -d 選項。這是一個例子:
$ make -d | more GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.This program built for x86_64-pc-linux-gnu Reading makefiles… Reading makefile `Makefile'… Updating makefiles…. Considering target file `Makefile'. Looking for an implicit rule for `Makefile'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.o'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.c'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cc'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.C'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cpp'. Trying pattern rule with stem `Makefile'. --More--這是很長的輸出,你也看到我使用了 more 命令來一頁一頁顯示輸出。
4. 使用 -C 選項改變目錄
你可以為 make 命令提供不同的目錄路徑,在尋找 Makefile 之前會切換目錄的。這是一個目錄,假設你就在當前目錄下:
$ ls file file2 frnd frnd1.cpp log1.txt log3.txt log5.txt file1 file name with spaces frnd1 frnd.cpp log2.txt log4.txt但是你想運行的 make 命令的 Makefile 文件保存在 ../make-dir/ 目錄下,你可以這樣做:
$ make -C ../make-dir/ make: Entering directory `/home/himanshu/practice/make-dir' make: Nothing to be done for `all'. make: Leaving directory `/home/himanshu/practice/make-dir你能看到 make 命令首先切到特定的目錄下,在那執(zhí)行,然后再切換回來。
5. 通過 -f 選項將其它文件看作 Makefile
如果你想將重命名 Makefile 文件,比如取名為 my_makefile 或者其它的名字,我們想讓 make 將它也當成 Makefile,可以使用 -f 選項。
make -f my_makefile通過這種方法,make 命令會選擇掃描 my_makefile 來代替 Makefile。
?
?
?
參考文章
詳解linux下make命令的使用方法
?
?
總結
以上是生活随笔為你收集整理的Ubuntu之make:make命令行工具的简介、安装、使用方法之详细攻略的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HighNewTech:70后、80后、
- 下一篇: DL之SSD:SSD算法的简介(论文介绍