當前位置:
首頁 >
gcc入门手册
發(fā)布時間:2024/8/1
34
豆豆
gcc入門介紹
- 查看GCC手冊
- 查看gcc版本
- gcc支持的文件
- gcc編譯過程
- gcc的常用選項
查看GCC手冊
GCC手冊在線閱讀
GCC手冊英文pdf版本
GCC手冊中文pdf版本
C語言中文網的GCC簡介
查看gcc版本
#gcc -vgcc支持的文件
gcc編譯過程
編譯過程并不是一步到位的,分為預編譯、編譯、匯編、鏈接。
預處理:源文件.c --> 處理后的源文件.i
編譯:源文件.i --> 匯編文件.s
匯編:匯編文件.s -->目標文件.o
鏈接:可重定位目標文件.o --> 可執(zhí)行目標文件(ELF)
但是如果直接gcc hello.c,就會“直接”生成一個可執(zhí)行文件a.out,其實中間的過程還是會包括預處理、編譯、匯編、鏈接四個過程,只不過是在內部實現了。
那平時為什么不直接生成執(zhí)行文件?
gcc的常用選項
#gcc --help zhouyuanlin@zhouyuanlin-virtual-machine:/mnt/hgfs/share$ gcc --help Usage: gcc [options] file... Options:-pass-exit-codes Exit with highest error code from a phase--help Display this information--target-help Display target specific command line options--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]Display specific types of command line options(Use '-v --help' to display command line options of sub-processes)--version Display compiler version information-dumpspecs Display all of the built in spec strings-dumpversion Display the version of the compiler-dumpmachine Display the compiler's target processor-print-search-dirs Display the directories in the compiler's search path-print-libgcc-file-name Display the name of the compiler's companion library-print-file-name=<lib> Display the full path to library <lib>-print-prog-name=<prog> Display the full path to compiler component <prog>-print-multiarch Display the target's normalized GNU triplet, used asa component in the library path-print-multi-directory Display the root directory for versions of libgcc-print-multi-lib Display the mapping between command line options andmultiple library search directories-print-multi-os-directory Display the relative path to OS libraries-print-sysroot Display the target libraries directory-print-sysroot-headers-suffix Display the sysroot suffix used to find headers-Wa,<options> Pass comma-separated <options> on to the assembler-Wp,<options> Pass comma-separated <options> on to the preprocessor-Wl,<options> Pass comma-separated <options> on to the linker-Xassembler <arg> Pass <arg> on to the assembler-Xpreprocessor <arg> Pass <arg> on to the preprocessor-Xlinker <arg> Pass <arg> on to the linker-save-temps Do not delete intermediate files-save-temps=<arg> Do not delete intermediate files-no-canonical-prefixes Do not canonicalize paths when building relativeprefixes to other gcc components-pipe Use pipes rather than intermediate files-time Time the execution of each subprocess-specs=<file> Override built-in specs with the contents of <file>-std=<standard> Assume that the input sources are for <standard>--sysroot=<directory> Use <directory> as the root directory for headersand libraries-B <directory> Add <directory> to the compiler's search paths-v Display the programs invoked by the compiler-### Like -v but options quoted and commands not executed-E Preprocess only; do not compile, assemble or link-S Compile only; do not assemble or link-c Compile and assemble, but do not link-o <file> Place the output into <file>-pie Create a position independent executable-shared Create a shared library-x <language> Specify the language of the following input filesPermissible languages include: c c++ assembler none'none' means revert to the default behavior ofguessing the language based on the file's extensionOptions starting with -g, -f, -m, -O, -W, or --param are automaticallypassed on to the various sub-processes invoked by gcc. In order to passother options on to these processes the -W<letter> options must be used.For bug reporting instructions, please see: <file:///usr/share/doc/gcc-5/README.Bugs>.方便大家查看,這里找了一個翻譯版本。
-pass-exit-codes 在某一階段退出時返回最高的錯誤碼--help 顯示此幫助說明--target-help 顯示目標機器特定的命令行選項--help={target|optimizers|warnings|params|[^]{joined|separate|undocumented}}[,...] //顯示特定類型的命令行選項(使用‘-v --help’顯示子進程的命令行參數)--version 顯示編譯器版本信息-dumpspecs 顯示所有內建 spec 字符串-dumpversion 顯示編譯器的版本號-dumpmachine 顯示編譯器的目標處理器-print-search-dirs 顯示編譯器的搜索路徑-print-libgcc-file-name 顯示編譯器伴隨庫的名稱-print-file-name=<庫> 顯示 <庫> 的完整路徑-print-prog-name=<程序> 顯示編譯器組件 <程序> 的完整路徑-print-multi-directory 顯示不同版本 libgcc 的根目錄-print-multi-lib 顯示命令行選項和多個版本庫搜索路徑間的映射-print-multi-os-directory 顯示操作系統庫的相對路徑-print-sysroot 顯示目標庫目錄-print-sysroot-headers-suffix 顯示用于尋找頭文件的 sysroot 后綴-Wa,<選項> 將逗號分隔的 <選項> 傳遞給匯編器-Wp,<選項> 將逗號分隔的 <選項> 傳遞給預處理器-Wl,<選項> 將逗號分隔的 <選項> 傳遞給鏈接器-Xassembler <參數> 將 <參數> 傳遞給匯編器-Xpreprocessor <參數> 將 <參數> 傳遞給預處理器-Xlinker <參數> 將 <參數> 傳遞給鏈接器-combine 將多個源文件一次性傳遞給匯編器-save-temps 不刪除中間文件-save-temps=<arg> 不刪除中間文件-no-canonical-prefixes 生成其他 gcc 組件的相對路徑時不生成規(guī)范化的前綴-pipe 使用管道代替臨時文件-time 為每個子進程計時-specs=<文件> 用 <文件> 的內容覆蓋內建的 specs 文件-std=<標準> 指定輸入源文件遵循的標準--sysroot=<目錄> 將 <目錄> 作為頭文件和庫文件的根目錄-B <目錄> 將 <目錄> 添加到編譯器的搜索路徑中-b <機器> 為 gcc 指定目標機器(如果有安裝)-V <版本> 運行指定版本的 gcc(如果有安裝)-v 顯示編譯器調用的程序-### 與 -v 類似,但選項被引號括住,并且不執(zhí)行命令-E 僅作預處理,不進行編譯、匯編和鏈接-S 編譯到匯編語言,不進行匯編和鏈接-c 編譯、匯編到目標代碼,不進行鏈接-o <文件> 輸出到 <文件>-x <語言> 指定其后輸入文件的語言,允許的語言包括:c c++assembler none‘none’意味著恢復默認行為,即根據文件的擴展名猜測源文件的語言以 -g、-f、-m、-O、-W 或 --param 開頭的選項將由 g++/gcc 自動傳遞給其調用的不同子進程。若要向這些進程傳遞其他選項,必須使用 -W<字母> 選項。通過gcc --help可以查看gcc的選項,主語區(qū)分大小寫。不過其實常用的也就是十多個選項。
總結
- 上一篇: 拆机清灰重装系统数据恢复——心得汇总
- 下一篇: Go_入坑笔记