一GCC學得的知識總結
(1)
編譯鏈接gcc hello.c -o hello
只編譯不鏈接gcc -c hello.c
如果出現gcc -c hello.c -o hello;則會報錯
[root@embedclub gcc]# gcc -c hello -o hello
gcc: hello:未使用鏈接器輸入文件,因爲鏈接尚未完成
產生調試信息gcc -g hello.c -0 hello
-rwxrwxr-x 1 root root 5743 5月 21 09:16 hello //加小d,5743變大
-rwxrwxr-x 1 root root 4639 5月 21 09:17 hello //不加小d,4639相對小
優化,速度快gcc -O hello.c -0 hello
查看時間長短time ./hello
[root@embedclub gcc]# gcc -O hello.c -o hello
[root@embedclub gcc]# ls
hello hello.c hello.o
[root@embedclub gcc]# time ./hello
hello world
real 0m0.001s
user 0m0.000s
sys 0m0.000s
[root@embedclub gcc]# rm hello
rm:是否刪除普通文件 "hello"?y
[root@embedclub gcc]# gcc hello.c -o hello
[root@embedclub gcc]# time ./hello
hello world
real 0m0.001s
user 0m0.000s
sys 0m0.001s
[root@embedclub gcc]#
生成警告信息gcc -Wall hello.c -0 hello
不生產警告信息gcc -w hello.c -0 hello
-YES(大寫的字母)相當與在程序裏使用宏定義#define YES
(2)
靜態鏈接與動態鏈接
靜態:每個文件裏都有.h
動態:去調用固定文件裏的.h
這裏出了問題,編譯不成功
(3)
linux頭文件在/usr/include/
而自己編寫的頭文件,
pwd查看當前目錄
在編譯時gcc -I/home/lesson/part1 hello.c -o hello
[root@embedclub gcc]# touch a.h
[root@embedclub gcc]# ls
a.h hello.c
[root@embedclub gcc]# pwd
/home/embedclub/yingyong_test/gcc
[root@embedclub gcc]# gcc -I/home/embedclub/yingyong_test/gcc hello.c -o hello
[root@embedclub gcc]# ls
a.h hello hello.c
[root@embedclub gcc]#
二GDB學得的知識總結
(1)啓動調試的兩種方式:
第一種
gdb test//啓動起來
b main//打斷點
run//運行
n//一步一步運行
c//直接全部運行
第二種
gdb
file test
(2)
l //查看程序
b 函數名 //在函數入口處添加斷點
b 行號 //在指定行添加斷點
b file:行號 //在指定文件的指定行號添加斷點
(3)
info b //查看斷點信息
delete 1//刪除斷點1
print 1 //查看斷點一處信息
n//單步執行
s//單步執行(不進子函數)
(4)quit //退出調試
三編譯makefile的總結
(1)
目標 依賴 命令
main.o : main.c
gcc -c main.c
(2)
$^代表所有依賴文件
$@代表所有目標文件
$<代表第一個依賴文件