gcc [option] file...
preprocessing compilation assembly linking
.c(with macros)--->.c(without macros)--->assembler input file--->object file--->executable file
-E, -S, -c 告诉在编译哪一个阶段中止。
-E 在执行 preprocessing 后中止,产生标准输出。
-S 在执行 compilation 后中止,产生 .s 文件。
-c 在执行 assembly 后中止,产生 .o 文件。
-std 指定编译器使用的标准。经常使用标准:c90, c89(就是c90), c99, gnu90(default), gnu99, c++98, gnu++98。示例:-std=c90。
-ansi for C code 等价 -std=c90。-ansi for C++ code 等价 -std=c++98。
-pedantic Issue all the warnings demanded by strict ISO C and ISO C++;
reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++.
需配合 -std 或 -ansi 使用。
-g 添加标准调试信息。另外一个选项 -ggdb,添加对 gdb 更友好的调试信息。
-pg 当想使用性能分析工具 gprof 时,须要添加该选项。
-O 优化(Optimize)。经常使用可选值:-O0(default), -O1(等价 -O), -O2(通常使用的优化级别), -O3, -Os(针对空间优化)。
-Wall 开启全部提醒。-Werror 把提醒看成错误。
-I 添加 include 目录。
-L 添加 lib 目录。
-l 将库文件添加到连接过程当中,默认是连接 shared libraries。下面是为何把 -l 放到命令行最后的缘由。
It makes a difference where in the command you write this option;
the linker searches and processes libraries and object files in the
order they are specified. Thus, foo.o -lz bar.o searches library z
after file foo.o but before bar.o. If bar.o refers to functions in
z, those functions may not be loaded.
-static 强制使用 static linking 来连接库(gcc 默认使用 shared linking, 不成功再试用 static linking)。连接库时有两种选择:static linking(*.a, archive file), dynamic linking(*.so, shared object)。
-shared
Produce a shared object which can then be linked with other objects
to form an executable.
-Dmacro[=defn] 定义 macro。
-U 取消 macro 的定义。该 macro 能够是 either built in or provided with a -D option。
-o 定义 output 文件名。
-f Options of the form -fflag specify machine-independent flags.应该不经常使用吧。
-fPIC emit position-independent code, suitable for dynamic linking and avoiding any limit on the
size of the global offset table.
-m Each target machine types can have its own special options, starting
with -m, to choose among various hardware models or
configurations---for example, 68010 vs 68020, floating coprocessor or
none. A single installed version of the compiler can compile for any
model or configuration, according to the options specified.应该不经常使用吧。