选项 | 参数 | 描述 | 例子 |
-x | 'c|c++|..|' | 不再根据源文件的后缀名来判断编写源文件的语言,即指定源文件的语言 | g++ -x 'c++' test.txt |
-E |
| 只执行编译的第一个流程:预处理,不会生成文件,可以重定向到文件 | g++ -E test.cpp |
-S |
| 执行编译的前两个流程生成汇编代码 | g++ -S test.cpp |
-c |
| 执行前三个流程生成目标文件 | g++ -c test.cpp |
-o | 目标文件名 | 重命名目标文件名 | g++ -S -o test.asm test.cpp |
-pipe |
| 使用管道来存储文件,下一个流程从/tmp/文件夹中读取上一个流程的结果,使用pipe后,上一个流程将结果保存在内存中,下一个流程直接从内存中读取上一个流程的结果 | g++ -pipe -o test.exe test.cpp |
-ansi |
| 关闭gun的特性,使代码全面符合ansi要求,从而具有高移植性 | g++ -ansi -o test.ext test.cpp |
-fno-asm |
| -ansi的一部分:将asm,inline,typeof视为普通标识符 | g++ -fno-asm -o test.exe test.cpp |
-fno-strict-prototype |
| 不再支持 |
|
-fthis-is-variable |
| 不再支持 |
|
-fcond-mismatch |
| 允许条件表达式的第2,3个参数的类型不一致,现已默认开启 | 默认开启 |
-funsigned-char -fno-signed-char -fsigned-char -fno-unsigned-char |
| 对char类型进行设置,决定将char类型设置成unsigned char(前两个参数)或者signed char(后两个参数) |
|
-imacros | 包含宏的文件 | 相当于include,可以直接使用参数文件里的宏 | g++ -imacros hello.mac hello.cpp |
-Dmacro -Dmacro=defn | macro为参数 | 相当于#define macro | g++ -DUNICODE -o test.exe hello.cpp |
-Umacro | macro为参数 | 相当于#undef macro,不能取消在文本文件中定义的宏! | g++ -UUNICODE -o test.exe hello.cpp |
-undef |
| 取消对任何非标准宏的定义 | g++ -undef -o test.exe hello.cpp |
-Idir | dir就是参数 | 一般查找头文件顺序:-I指定的目录->当前目录->环境变量定义的目录 | g++ -I'C:/Users/Dream/Desktop/' -o test.exe hello.cpp |
-nostdinc |
| 使编译器不在系统缺省的头文件目录里面找头文件 | g++ -nostdinc -o test.exe -c hello.cpp |
-C |
| 在预处理的时候,不删除注释信息,一般和-E使用,有时候分析程序,用这个很方便的 | g++ -E -C -o test.h hello.cpp |
-M |
| 生成文件关联的信息。包含目标文件所依赖的所有源文件,这个在制作makefile应该会很有用 | g++ -M -o test1.h hello.cpp |
-MM |
| 同-M,不过忽略#include>造成的依赖关系 | g++ -MM -o test.h hello.cpp |
-Wa | options | 传递参数给as(汇编器) |
|
-Wl | options | 传递参数为ld(连接器) |
|
-llibs | lib就是参数 | 指定编译的时候所使用的库,liblibs.so(如果static选项设置的话就是liblibs.a) | g++ -lprint hello.cpp(链接 libprint.so) |
-Ldir | dir就是参数 | 指定查找链接库时的目录 | g++ -L'C:/Users/Dream/Desktop/' -lprint hello.cpp |
-On | n为参数,表示优化等级取:0,1,2,3 | 进行相应程度的优化 | g++ -O3 -o test3.asm -S hello.cpp |
-g -ggdb -gstabs -gstabe+ |
| 生成调试信息,可以被gdb使用 尽可能地生成gdb格式的调试信息 生成stabs格式的调试信息 同时shengc stabs,gdb格式的信息 | g++ -g hello.cpp |