今天大概瀏覽了下《UnixProgrammingTools》, 知道了一下幾方面的基本知識(shí)。
- gcc編譯器的使用
- make
gcc
學(xué)習(xí)了gcc的基本指令,以前只知道-c、-o的用法,此次學(xué)會(huì)了更多的指令
- -g
增加調(diào)試信息,方便使用gdb進(jìn)行調(diào)試
- -Wall
在源代碼中可能出錯(cuò)的地方給出警告
- -Idir
添加頭文件所在的路徑
- -Ldir
添加庫(kù)文件所在的路徑
- -lmylib
添加庫(kù)文件的名稱,注意庫(kù)文件的順序,被依賴的文件必須放在依賴文件之前
make
使用make工具可以大大減少編譯、鏈接時(shí)的工作量。
makefile文件
變量
makefile中的變量相當(dāng)于C語(yǔ)言中的宏。當(dāng)沒(méi)有對(duì)一個(gè)變量賦值時(shí),其值為空。變量的使用方法如下,eg:
定義變量:CC = gcc
使用變量:$(CC)
dependency/build rule
A rule tells how to make a target based on changes to a list of certain files. The order of rules does not make any difference, except that the first rule is consider to be the default rule -- the rule that will be invoked when make is called without any arguments (the most common way).