gcc 編譯心得一

c/c++ 在linux 環境編譯下,在編譯配置處理上某些參數的中文理解.
-shared : 連接器選項...告訴連接器產生一個共享目標文件. 一旦用這個選項,其他共享目標文件選擇也是一樣的,要麼-fpic或-fPIC

-fpic:編譯器就輸出位置無關目標碼, 16k,32k範圍轉移.
-fPIC:編譯器就輸出位置無關目標碼, 大範圍轉移,現在都用這個.

-I dir: Adds dir to the list of directories searched for header files.
增加頭文件查找的路徑
-L dir Adds dir to the list of directories searched for library files.
增加庫文件查找的路徑.

-rpath libdir: Specifies that a library you are linking will eventually be installed in the
directory libdir.

-R libdir: Adds the specified directory (libdir) to the runtime path of the programs and
libraries that you are linking.

pkg-config的用法
pkg-config用來獲得已經安裝的庫的信息.通常用來編譯和鏈接一個或多個庫.
pkg-config的一個常用用法是:
    cc program.c `pkg-config --cflags --libs glib-2.0`
  • --cflags 用來生成編譯那個庫所需要的compile flags
  • --libs 用來生成link flags
上例的輸出結果是

sunway@3[~]$ pkg-config --cflags --libs glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include  -lglib-2.0

MYINCLUDE = $(shell pkg-config --cflags gtk+-2.0 libpng xft)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章