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={target|optimizers|warnings|params|[^]{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-multi-directory Display the root directory for versions of libgcc
-print-multi-lib Display the mapping between command line options and
multiple 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
-combine Pass multiple source files to compiler at once
-save-temps Do not delete intermediate files
-save-temps=<arg> Do not delete intermediate files
-no-canonical-prefixes Do not canonicalize paths when building relative
prefixes 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 headers
and libraries
-B <directory> Add <directory> to the compiler's search paths
-b <machine> Run gcc for target <machine>, if installed
-V <version> Run gcc version number <version>, if installed
-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>
-x <language> Specify the language of the following input files
Permissible languages include: c c++ assembler none
'none' means revert to the default behavior of
guessing the language based on the file's extension
passed on to the various sub-processes invoked by gcc. In order to pass
other options on to these processes the -W<letter> options must be used.
<http://bugzilla.redhat.com/bugzilla>.
[gong@Gong-Computer Example]$ gcc -E main.c > main.pre.c
比如我將宏定義max(x,y)改寫為max (x,y)就會(huì)出現(xiàn)下面的結(jié)果。如下圖所示。
[gong@Gong-Computer Example]$ vi main.map
[gong@Gong-Computer Example]$ vi main.s
4、在gcc中函數(shù)庫(kù),鏈接庫(kù)的調(diào)用,這是比較難以掌握和容易出錯(cuò)的地方。
- foo.c
- 1 #include<stdio.h>
- 2
- 3
- 4 extern void bar();
- 5
- 6 void foo()
- 7 {
- 8 printf("This is foo ().\n");
- 9
- 10 bar ();
- 11 }
bar.c
1 #include<stdio.h>
2
3 void bar()
4 {
5 printf( " This is bar (). \n");
6 }
7
main.c
1 extern void foo();
2
3 int main()
4 {
5 foo();
6
7 return 0;
8 }
~
./libfoo.a(foo.o): In function `foo':
foo.c:(.text+0x13): undefined reference to `bar'
collect2: ld returned 1 exit status
以上的兩個(gè)編譯過(guò)程只是存在一個(gè)差異就是庫(kù)的擺放順序存在差別,第一種情況下由于foo依賴bar,而bar庫(kù)不能被foo調(diào)用,因此出錯(cuò)。而第二種則滿足foo依賴bar,main依賴foo的關(guān)系。其中的-L.表示庫(kù)函數(shù)的搜索目錄為當(dāng)前目錄。也可以換成其他的目錄。
動(dòng)態(tài)庫(kù)的使用可以將創(chuàng)建好的動(dòng)態(tài)庫(kù)放在/usr/lib下,然后在函數(shù)中即可實(shí)現(xiàn)調(diào)用。
- [gong@Gong-Computer test]$ gcc -M main.c
- main.o: main.c /usr/include/stdio.h /usr/include/features.h \
- /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
- /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \
- /usr/lib/gcc/i686-redhat-linux/4.5.1/include/stddef.h \
- /usr/include/bits/types.h /usr/include/bits/typesizes.h \
- /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
- /usr/lib/gcc/i686-redhat-linux/4.5.1/include/stdarg.h \
- /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h
- [gong@Gong-Computer test]$ gcc -MM main.c
- main.o: main.c
- [gong@Gong-Computer test]$
從上面的兩個(gè)結(jié)果就可以知道兩個(gè)選項(xiàng)的差別,這種差別在編寫Makefile中的依賴關(guān)系時(shí)非常的有用。特別是第二種形式是比較重要的方式。
關(guān)于gcc的使用還是要多實(shí)踐才有效果,才能準(zhǔn)確的運(yùn)用。