GCC Yi Options Turn

Source: Internet
Author: User
Tags builtin dbx

GCCProvides a number of warning options to warn about possible problems in your code, and you can usually use-wall to turn on the following warning:
-waddress-warray-bounds (only With-o2)-wc++0x-compat
-wchar-subscripts-wimplicit-int-wimplicit-function-declaration
-wcomment-wformat-wmain (only for C/OBJC and unless
-ffreestanding)-wmissing-braces-wnonnull-wparentheses
-wpointer-sign-wreorder-wreturn-type-wsequence-point
-wsign-compare (only in C + +)-wstrict-aliasing-wstrict-overflow=1
-wswitch-wtrigraphs-wuninitialized (only With-o1 and above)
-wunknown-pragmas-wunused-function-wunused-label-wunused-value
-wunused-variable
Unused-function: A warning statement but no defined static function;
Unused-label: A label that is declared but not used;
Unused-parameter: Warning of unused function parameters;
Unused-variable: a local variable declared but not used;
Unused-value: Calculated but not used values;
Improper use of format strings in functions such as format:printf and scanf;
Implicit-int: no type specified;
Implicit-function: Functions are used before declarations;
Char-subscripts: Use the Char class as an array subscript (because Char may be a signed number);
Missingbraces: Curly braces do not match;
Parentheses: parentheses do not match;
Return-type: The function has no return value and the return value type does not match;
Sequence-point: Code that violates the order point, such as a[i] = c[i++];
The Switch:switch statement lacks a case where the default or switch is missing a variable when using an enumeration variable as an index;
Strict-aliasing=n: Use N to set the limit on the type of object to which the pointer variable points, by default n=3; only if the-fstrict-aliasing setting is valid;
Unknow-pragmas: Use of unknown #pragma instructions;
Uninitialized: The variables used are initialized, only valid at-o2;

The following are the warning options that will not be activated in-wall:
Cast-align: A warning is issued when the pointer has a more stringent memory alignment requirement after the type conversion;
Sign-compare: When comparing with signed and unsigned types;
Missing-prototypes: When the function has no function prototype before use;
packed:packed is an extension of GCC, which is required to keep memory alignment between members of the structSpace, sometimes causing memory alignment problems;
Padded: is also an extension of GCC, which causes the structure body to increase in size by making a memory-aligned fill between members.
Unreachable-code: There is no code to execute when.
Inline: When the inline function is no longer holding inline (for example, the inline function takes an address);
Disable-optimization: When the specified optimization cannot be performed. (Requires too much time orsystemResources).
When you can use-werror, all warnings become errors, and the compilation is stopped when a warning occurs. You need to use the parameter with the specified warning.

Optimization:
GCC provides a collection of Level 5 optimization options by default:
-o0: No optimization (default)
-O and-o1: use to reduce targetsfileThe size and execution time without significantly increasing compilation time. When compiling large programs, it can significantly increase the use of compile-time memory.
-O2: Contains optimizations for-O1 and adds optimizations that do not require compromise between the target file size and execution speed. The compiler does not perform loop expansion and function inline. This option increases the compilation time and execution performance of the target file.
-os: Specifically optimizes the target file size and performs all-O2 optimization options that do not increase the size of the target file. and perform optimization options that specifically reduce the size of the target file.
-o3: Turn on all-o2 optimization options and add-finline-functions,-funswitch-loops,-fpredictive-commoning,-fgcse-after-reload and- Ftree-vectorize optimization options.

-O1 contains options that are commonly used in conjunction with-O1 options, which are safe and debug:
-fauto-inc-dec-fcprop-registers-fdce-fdefer-pop-fdelayed-branch
-fdse-fguess-branch-probability-fif-conversion2-fif-conversion
-finline-small-functions-fipa-pure-const-fipa-reference
-fmerge-constants-fsplit-wide-types-ftree-ccp-ftree-ch
-ftree-copyrename-ftree-dce-ftree-dominator-opts-ftree-dse
-ftree-fre-ftree-sra-ftree-ter-funit-at-a-time

All of the following optimization options need to precede the first name with-F, and if this option is not required, you can use the-fno-prefix
Defer-pop: Delay to the pop parameter from the function parameter stack only when necessary;
Thread-jumps: Use jump thread optimization to avoid jumping to another jump;
Branch-probabilities: Branch optimization;
Cprop-registers: Use copy-propagation to transmit values between registers;
Guess-branch-probability: Branch prediction;
Omit-frame-pointer: The stack frame is not generated in the possible case;

-o2: The following are the optimization options that-o2 adds to the-o1 base:
-falign-functions-falign-jumps-falign-loops-falign-labels
-fcaller-saves-fcrossjumping-fcse-follow-jumps-fcse-skip-blocks
-fdelete-null-pointer-checks-fexpensive-optimizations-fgcse
-fgcse-lm-foptimize-sibling-calls-fpeephole2-fregmove
-freorder-blocks-freorder-functions-frerun-cse-after-loop
-fsched-interblock-fsched-spec-fschedule-insns
-fschedule-insns2-fstrict-aliasing-fstrict-overflow-ftree-pre
-ftree-vrp
Optimization options for CPU architecture, usually-MCPU (will be canceled);-march,-mtune

Debug options:
Specifying the-G option when GCC compiles the source code can produce the target code with debug information, and GCC can provide debugging information for different different platforms God debugger, the default GCC generated debugging information is used for GDB, you can use-gformat Specifies the format of debug information to be generated for use by other debuggers that are available to other platforms. Common formats are
-ggdb: To generate GDB-specific debugging information, using the most appropriate format (DWARF 2,stabs, etc.) will have some GDB-specific extensions that may cause other debuggers to fail to run.
-gstabs: Using the stabs format, which does not include GDB extensions, stabs is commonly used in the DBX debugger of BSD systems.
-gcoff: Produces debug information in the COFF format, commonly used in the SDB debugger under System V;
-gxcoff: produces debug information in Xcoff format for the DBX debugger under IBM rs/6000;
-gdwarf-2: Produces debug information in Dwarf Version2 format, commonly used in the DBX debugger on IRIXX6. GCC uses some of the features of dwarf version3.
You can specify the level of debug information: Add a level after the specified debug format:
such as:-GGDB2, etc., 0 means no debug information. When using-gdwarf-2, because the earliest format is-GDWARF2, it causes confusion, so you need to use a-glevel to specify the level of debug information, and other formatting options can also be assigned a different level.

GCC can use the-P option to specify the build information for Porf use.

GCC Common options

Options meaning
--help
--target-help
Displays the GCC help description. ' Target-help ' is a command-line option that displays target machine-specific.
--version Displays the GCC version number and copyright information.
-O outfile Output to the specified file.
-Xlanguage Indicates the programming language used. The allowed languages include: C C + + assembler none. ' None ' means restoring the default behavior, which is to guess the language of the source file based on the file extension.
-V Prints more information, showing the program that the compiler called.
-### Similar to-V, but the option is enclosed in quotation marks and the command is not executed.
-E preprocessing only, without compiling, compiling, and linking. As shown in.
-S Compiled into assembly language only, not compiled and linked. As shown in.
-C Compile, assemble to target code, do not link. As shown in.
-pipe Use pipelines instead of temporary files.
-combine Pass multiple source files to the assembler at once.

3 Other GCC options

More useful gcc options:

Standard Machine
Command Description
-L Library
-LLibrary
Search for libraries named Library when making links.
Example: $ gcc test.c-lm-o test
-I.dir Add dir to the path list of the search header file.
Example: $ gcc test.c-i. /inc-o Test
-Ldir Add dir to the path list of the search library file.
Example: $ gcc-i/home/foo-l/home/foo-ltest test.c-o test
-DName A macro named name is predefined, with a value of 1.
Example: $ gcc-dtest_config test.c-o test
-Dname=definition A macro named namewith a value of definition is predefined.
-ggdb
-ggdb Level
Generates debug information for the debugger gdb. level can be in 2, and the default value is.
-G
- G level
Generates debug information for the operating system local format. -G and-ggdb are not the same, and-G generates information outside of GDB. level value as above.
-S Removes symbol tables and relocation information from the executable file. Used to reduce the size of the executable file.
-M Tells the preprocessor to output a rule that is appropriate for make to describe the dependencies of each target file. For each source file, the preprocessor outputs a make rule where the target entry (target) of the source file corresponds to the destination file name, and the dependency (dependency) is the ' #include引用的所有文件 in the source file. The generated rule can be a single row, but if it is too long, use '/'-line Fu Yi into multiple lines. The rules are displayed in standard output and do not produce pre-processed C programs.
-C Tells the preprocessor not to discard comments. Use with the '-e ' option.
-P Tell the preprocessor not to produce a ' #line ' command. Use with the '-e ' option.
-static Block connections to shared libraries on systems that support dynamic linking. This option is not valid on other systems.
-nostdlib No system standard boot files and standard library files are connected, only the specified files are passed to the connector.
Warnings  
-wall Some useful warning options are turned on, and it is recommended to compile with this option.
-W
-wextra
Print some additional warning messages.
-W Suppresses the display of all warning messages.
-wshadow A warning is given when a local variable obscures another local variable, or a global variable. Useful option, it is recommended to open. -wall does not open this entry.
-wpointer-arith A warning is given when arithmetic operations are performed on a function pointer or a pointer of type void *. is also very useful. -wall does not open this entry.
-wcast-qual A warning is given when a cast loses a type modifier. -wall does not open this entry.
-waggregate-return If a function that returns a struct or union is defined or called, the compiler warns.
-winline Whether the declaration is inline or the-finline-functions option is specified, the compiler will issue a warning if a function cannot be inline. This is a useful option if your code contains many inline functions.
-werror Treat the warning as an error. Discard the compilation if any warnings occur.
-wunreachable-code If the compiler detects code that is never executed, a warning is given. is also a more useful option.
-wcast-align The compiler warns you when a pointer-type cast causes the desired address alignment for the target to increase.
-wundef A warning is given when a symbol that is not defined appears in the #if.
-wredundant-decls If a definition is declared multiple times within the same visible domain, the compiler warns you, even if the duplicate declarations are valid and are not different.
optimization  
-o0 Prevents the compiler from being optimized. Default for this item.
-O
-o1
Try to optimize compilation time and executable file size.
-o2 More optimizations will try almost all of the optimizations, but not the "space-for-time" optimization method.
-o3 On the basis of-O2 to open some of the optimization options:-finline-functions,-funswitch-loops and-fgcse-after-reload.
-os Optimizes the size of the build file. It will open all the options-o2 open, except those that increase the file size.
-finline-functions Put all the simple functions inline into the caller. The compiler will explore what functions are simple enough to be worth doing inline.
-fstrict-aliasing Apply the strongest alias rule (aliasing rules).
 
-ansi Supports C programs that conform to ANSI standards. This will turn off some of the incompatible ANSI C features in GNU C.
-std=c89
-iso9899:1990
Indicates that the program is compiled using standard ISO C90 as a standard.
-std=c99
-std=iso9899:1999
Indicates that the program is compiled using standard ISO C99 as a standard.
-std=c++98 Indicates that the program is compiled using standard c++98 as a standard.
-std=gnu9x
-std=gnu99
Use ISO C99 plus some of the GNU extensions.
-fno-asm ASM, inline, or typeof are not treated as keywords, so these words can be used as identifiers. With __asm__, __inline__ and __typeof__ can replace them. The '-ansi ' implicitly declares '-fno-asm '.
-fgnu89-inline Tells the compiler to use the traditional GNU syntax when it sees the inline function in C99 mode.
C Options  
-fsigned-char
-funsigned-char
Define char as a/unsigned type, as signed char/unsigned Char.
-traditional Try to support some aspects of the traditional C compiler. See the GNU C Manual.
-fno-builtin
-fno-builtin-function
Functions that do not have __builtin_ prefixes are not accepted as built-in functions.
-trigraphs A triple character (trigraphs) that supports ANSI C. The '-ansi ' option implicitly declares this option.
-fsigned-bitfields
-funsigned-bitfields
If the ' signed ' or ' unsigned ' modifier is not explicitly declared, these options are used to define the signed bit field or the unsigned bit field. By default, bit fields are signed because they inherit the base integer type, such as int, which is a signed number.
-wstrict-prototypes If the declaration or definition of a function does not indicate a parameter type, the compiler warns you. A useful warning.
-wmissing-prototypes If a global function is defined without a pre-declaration, the compiler warns. This warning is generated even if the function definition itself provides a prototype of the function. The purpose of this option is to check for global functions that are not declared in the header file.
-wnested-externs If an extern declaration appears inside the function, the compiler issues a warning.
C + + options  
-ffor-scope Execute the program from the beginning, and also allow redirection.
-fno-rtti Turn off support for dynamic_cast and typeID. If you don't need these features, turning it off will save you some space.
-wctor-dtor-privacy Give a warning when a class is not available. Because constructors and destructors are treated as private.
-wnon-virtual-dtor A warning is issued when a class has polymorphism without a virtual destructor. -wall will open this option.
-wreorder If the initialization order of member variables in the code is inconsistent with the order in which they were actually executed, a warning is given.
-wno-deprecated Do not give a warning when using outdated features.
-woverloaded-virtual If the declaration of the function hides the virtual function of the base class, a warning is given.
Dependent Options (Intel)  
-mtune=Cpu-type Generates code for the specified type of CPU. Cpu-type can be: I386,i486,i586,pentium,i686,pentium4 and so on.
-msse
-msse2
-mmmx
-mno-sse
-mno-sse2
-mno-mmx
Use or do not use the MMX,SSE,SSE2 directive.
-m32
-m64
Generate code on 32-bit/64-bit machines.
-mpush-args
-mno-push-args
(not) Use the push instruction to store parameters. The default is to use.
-mregparm=Num Controls the number of registers that are used when passing integer parameters.

Other than that:

When the static library and the dynamic library have the same name, the GCC command takes precedence over the dynamic library.

-shared This option specifies to generate a dynamic connection library (let the connector generate the export symbol table of type T, and sometimes the export symbol of the weakly connected W type) without which the external program cannot connect. Equivalent to an executable file
L-fpic: represents compiled to a location-independent code, without this option, the compiled code is location-dependent, so dynamic loading is a way of copying code to meet the needs of different processes, but not to achieve the purpose of real code segment sharing.
L-l.: Indicates the library to be connected in the current directory
L-ltest: The compiler has an implicit naming convention when looking for dynamic connection libraries, which is to precede the given name with Lib, followed by. So to determine the name of the library
L Ld_library_path: This environment variable indicates that the dynamic connector can load the path of the dynamic library.
L Of course, if you have root permissions, you can modify the/etc/ld.so.conf file, and then call/sbin/ldconfig to achieve the same goal, but if you do not have root privileges, you can only use the output Ld_library_path method. Call the dynamic library when there are several problems often encountered, and sometimes, clearly has the library's header file in the directory through the "-I" include, the library is located in the file through the "-l" parameter boot, and specified the "-L" library name, but through the LDD command to see, it is dead and alive can not find your designated link , you have to specify the directory of the dynamic library by modifying the Ld_library_path or/etc/ld.so.conf file. This is usually done to solve the problem where the library cannot be linked.

GCC Yi Options Turn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.