Gcc的常用编译选项

本文最后更新于2017年8月18日,已超过 1 年没有更新,如果文章内容失效,还请反馈给我,谢谢!

=Start=

缘由:

学习、提高需要

正文:

参考解答:

==

总体选项(Overall Option)

-c -S -E -o file -pipe -v -x language

语言选项(Language Option)

-ansi -fall-virtual -fcond-mismatch -fdollars-in-identifiers -fenum-int-equiv -fexternal-templates -fno-asm -fno-builtin -fhosted -fno-hosted -ffreestanding -fno-freestanding -fno-strict-prototype -fsigned-bitfields -fsigned-char -fthis-is-variable -funsigned-bitfields -funsigned-char -fwritable-strings -traditional -traditional-cpp -trigraphs

警告选项(Warning Option)

-fsyntax-only -pedantic -pedantic-errors -w -W -Wall -Waggregate-return -Wcast-align -Wcast-qual -Wchar-subscript -Wcomment -Wconversion -Wenum-clash -Werror -Wformat -Wid-clash-len -Wimplicit -Wimplicit-int -Wimplicit-function-declaration -Winline -Wlong-long -Wmain -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wno-import -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wswitch -Wtemplate-debugging -Wtraditional -Wtrigraphs -Wuninitialized -Wunused -Wwrite-strings

调试选项(Debugging Option)

-a -dletters -fpretend-float -g -glevel -gcoff -gxcoff -gxcoff+ -gdwarf -gdwarf+ -gstabs -gstabs+ -ggdb -p -pg -save-temps -print-file-name=library -print-libgcc-file-name -print-prog-name=program

优化选项(Optimization Option)

-fcaller-saves -fcse-follow-jumps -fcse-skip-blocks -fdelayed-branch -felide-constructors -fexpensive-optimizations -ffast-math -ffloat-store -fforce-addr -fforce-mem -finline-functions -fkeep-inline-functions -fmemoize-lookups -fno-default-inline -fno-defer-pop -fno-function-cse -fno-inline -fno-peephole -fomit-frame-pointer -frerun-cse-after-loop -fschedule-insns -fschedule-insns2 -fstrength-reduce -fthread-jumps -funroll-all-loops -funroll-loops -O -O2 -O3

预处理器选项(Preprocessor Option)

-Aassertion -C -dD -dM -dN -Dmacro[=defn] -E -H -idirafter dir -include file -imacros file -iprefix file -iwithprefix dir -M -MD -MM -MMD -nostdinc -P -Umacro -undef

汇编器选项(Assembler Option)

-Wa,option

连接器选项(Linker Option)

-llibrary -nostartfiles -nostdlib -static -shared -symbolic -Xlinker option -Wl,option -u symbol

目录选项(Directory Option)

-Bprefix -Idir -I- -Ldir

目标机选项(Target Option)

-b machine -V version

配置相关选项(Configuration Dependent Option)

代码生成选项(Code Generation Option)

-fcall-saved-reg -fcall-used-reg -ffixed-reg -finhibit-size-directive -fnonnull-objects -fno-common -fno-ident -fno-gnu-linker -fpcc-struct-return -fpic -fPIC -freg-struct-return -fshared-data -fshort-enums -fshort-double -fvolatile -fvolatile-global -fverbose-asm

==

一些常用选项摘录:

参考链接:

GNU GCC 手册
http://www.shanghai.ws/gnu/gcc_1.htm

GCC基本用法 #nice
http://www.woola.net/detail/2016-09-10-gcc-tips.html

GCC编译选项 #nice
http://txgcwm.github.io/blog/2014/06/28/gccbian-yi-xuan-xiang/

GCC Command Options
https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html

GCC警告选项例解
http://tonybai.com/2006/03/14/explain-gcc-warning-options-by-examples/

gcc编译器学习记录
https://github.com/guodongxiaren/LinuxTool/blob/master/gcc.md

[GCC/GDB/cygwin] gcc编译选项
http://www.airmyth.com/thread-1583-1-1.html

gcc的使用简介与命令行参数说明
http://blog.csdn.net/delphiwcdj/article/details/6555073

Gcc编译选项分析
http://www.cnblogs.com/showna/articles/1013401.html

GCC编译器总结
http://www.jianshu.com/p/b8ddb4cee7af

Linux GCC常用命令
http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2287738.html

Linux gcc编译参数 —- Werror的威力
http://www.leoox.com/?p=237

怎样学习GCC编译选项?
https://www.zhihu.com/question/28914753

=END=

声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!
https://ixyzero.com/blog/archives/3551.html

《Gcc的常用编译选项》上有7条评论

  1. Find libraries a binary was linked against
    https://superuser.com/questions/239590/find-libraries-a-binary-was-linked-against

    在Linux下,如何强制让GCC静态链接?
    https://www.zhihu.com/question/22940048/answer/222625910

    Linux编译安装openssl升级系统openssl和生成系统动态连接库dynamic/shared libraries
    https://www.zhangfangzhou.cn/update-openssl-and-dynamicshared-libr.html

    Linking OpenSSL libraries to a program
    https://stackoverflow.com/questions/4352573/linking-openssl-libraries-to-a-program

    How to Statically Link C and C++ Programs on Linux with gcc
    https://www.systutorials.com/5217/how-to-statically-link-c-and-c-programs-on-linux-with-gcc/

    Static link of shared library function in gcc
    https://stackoverflow.com/questions/725472/static-link-of-shared-library-function-in-gcc

    http://www.unix.com/programming/162567-linking-openssl-libcrypto-statically.html

    https://askubuntu.com/questions/454443/how-do-i-deal-with-undefined-reference-to-dlopen-errors-while-compiling-and-us

    How to link a library statically?
    http://hgesser.de/howto/static-link.html

    https://stackoverflow.com/questions/tagged/glibc


    1.首先要有静态库XYZ的文件(libXYZ.a);
    2.其次要在gcc链接选项中指定;
    3.最后使用ldd/readelf -d等命令测试一下;

  2. GCC 7.3 发布,这个版本新增了用于缓解“幽灵” Spectre CPU 漏洞的编译选项(CVE 2017-5715)
    https://gcc.gnu.org/ml/gcc/2018-01/msg00197.html
    https://www.solidot.org/story?sid=55353

    GCC 编译器项目释出了 7.3 版,新版本主要是修正 bug,包含了大量性能和安全问题的修正,其中最重要的是对 Retpoline 的支持,让 GCC 能用于构建抵抗 Spectre variant 2 漏洞的内核。Retpoline 是 Google 开发的补丁,能有效缓解 Spectre V2 漏洞,而且对性能影响甚微。它在 4.15-rc8 中合并到内核主线,但使用它需要编辑器支持,而在 GCC 7.3 之前还没有编译器支持 Retpoline。

发表评论

电子邮件地址不会被公开。 必填项已用*标注