GCC Preprocessor options

Source: Internet
Author: User

GCC Preprocessor options
Source:
Author:
Release date:

Font:
[Large
Medium
Small]

Preprocessor Option)

The following options are for the c Preprocessor, which is used to process the C source file before official compilation.

If'-E'Option. GCC only performs preprocessing. Some of the following options must be'-E'Options make sense, because their output results cannot be used for compilation.

-Include File
Before processing a regular input file, you must first process the file FileThe result is that the file FileFirst get the compilation. command line on any' -D'And' -U'Option is always on' -Include File'Previous processing, no matter how orderly they are on the command line. However' -Include'And' -Imacros'Options are processed in writing order.
-Imacros File
Before processing a regular input file, you must first process the file FileBut the output result is ignored. The file is discarded. FileThe output content ,' -Imacros File'The only effect of the option is to make the file FileThe macro definition in can be used for other input files. In processing' -Imacros File'Preprocessor first Process' -D'And' -U'Option, and do not care about their order on the command line. However' -Include'And' -Imacros'Options are processed in writing order.
-Idirafter Dir
Directory DirAdd to the second include path. If a header file is in the main include path (use' -IThe pre-processor searches for the second inclusion path.
-Iprefix Prefix
Specify PrefixAs follow' -Iwithprefix'Option prefix.
-Iwithprefix Dir
Add the directory to the second include path. The directory name is PrefixAnd DirMerged. Here PrefixBy the previous' -Iprefix'Option is specified.
-Nostdinc
Do not search for header files in the standard system directory. Only search' -I'Specifies the directory (and the current directory, if appropriate ).

Combined'-Nostdinc'And'-I-'Option, you can restrict the search containing files to explicitly specified directories.

-Nostdinc ++
Do not search for header files in the C ++ standard directory, but still search for other Standard Directories' Libg ++.)
-UNDEF
Do not predefine any non-standard macros (including system structure flag ).
-E
Only run C Preprocessor. pre-process all specified C source files and send the results to standard output or specified output files.
-C
Tell the Preprocessor not to discard comments. Cooperation' -E'Option.
-P
Tell the Preprocessor not to generate' # Line'COMMAND. core' -E'Option.
-M [-Mg]
Tells the Preprocessor output a suitable MakeTo describe the dependencies of each target file. For each source file, the pre-processor outputs MakeRule. The target item (target) of the rule is the target file name corresponding to the source file, and the dependency item (dependency) is' # IncludeAll referenced files. The generated rule can be a single line, but if it is too long, use' /'-The linefeed is continued to multiple rows. The rule is displayed in the standard output and no pre-processed C Programs are generated.

`-M'Implicit'-E'Option.

`-Mg'You need to treat the missing header files as existing, and assume that they are in the same directory as the source file. They must be'-M'Option used together.

-Mm [-Mg]
And' -M'Option is similar, but the output result only involves the user header file, like this' # Include File"'. Ignore system header files such' # Include < File> '.
-MD
And' -M'Option is similar, but the dependency information is output to the file, and the file name ends with the output file name' . O'Replace' . D'Generate. Continue the specified compilation work at the same time ---' -MD'Not taobao' -M'Blocks normal compilation tasks.

Mach utility'MD'Combiner'. D'File, which is applicable'Make'Single dependent file of the command.

-MMD
And' -MD'Option is similar, but the output only involves the user header file, ignoring the system header file.
-H
Besides other common operations, GCC displays referenced header file names.
- Question ( Answer )
If the Preprocessor performs a condition test, such' # If # Question ( Answer )', This option can be assert) QuestionThe answer is Answer. --'Disable standard assertions that are generally used to describe the target machine.
-D Macro
Definition macro MacroMacro content is defined as a string' 1'.
-D Macro = Defn
Definition macro MacroContent is Defn. All 'on the command line' -D'Option on' -U'Processing before the option.
-U Macro
Cancel macro Macro.' -U'Option on all' -D'Option is processed later, but it takes precedence over any' -Include'Or' -Imacros'Option.
-DM
Tells the Preprocessor to output a valid macro definition list (the macro definition still valid at the end of preprocessing). This option must be combined' -E'Option.
-Dd
Tells the Preprocessor to pass all macro definitions to the output end and display them in the displayed order.
-DN
And' -Dd'The option is similar, but the macro parameters or content are ignored. Only displayed at the output' # Define Name.
Assembler Option)
-Wa, Option
Set options OptionPassed to the assembler. If OptionIf there is a comma, separate the comma into multiple options.
Linker Option)

The following options are used by the compiler to connect to the target file and output executable files. They are meaningless if the compiler does not connect.

Object-file-name
If some files do not have a specific suffix a special recognized suffix, GCC considers them as the target file or library file. (depending on the file content, the connector can distinguish between the target file and the library file ). if GCC executes the connection operation, these target files will become the input files of the connector.
-L Library
Connection name LibraryLibrary file.

The connector looks for this library file in the standard search directory. the real name of the library file is'LibLibrary. A'. The connector will reference this file as the file name is exactly described.

In addition to some standard system directories'-L'Specifies the path.

Generally, the file found in this method is a library file, that is, an archive file consisting of the target file ). the connector can process archive files by scanning archive files to find some Members whose symbols have been referenced but not yet defined. however, if the connector finds a common target file instead of a library file, it connects the target file in the usual way. specify'-L'The only difference between the option and the specified file name is that ,'-LOption'Lib'And'.'PutLibraryPackage and search for directories.

-Lobjc
This -LThe special form of the option is used to connect to the Objective C program.
-Nostartfiles
The system standard Startup file is not connected, and the standard library file is still in normal use.
-Nostdlib
The system standard Startup File and standard library file are not connected. Only the specified file is passed to the connector.
-Static
Block the connection to the shared library on a system that supports dynamic connection (Dynamic Linking). This option is invalid on other systems.
-Shared
Generate a shared target file that can be connected to other target files to generate executable files. This option is only supported by some systems.
-Symbolic
When creating a shared target file, bind the reference to the global symbol. Warn all references that cannot be parsed (unless you use the connection edit option' -Xlinker-z-xlinker defs'Replace). Only some systems support this option.

-Xlinker Option
Set options OptionPassed to the connector. It can be used to pass system-specific connection options that gnu cc cannot recognize.

If you want to pass the option with parameters, you must use'-Xlinker', One option is passed, and another parameter is passed. For example, if'-Assert Definitions', You must write'-Xlinker-assert-xlinker Definitions', But not'-Xlinker "-assert definitions"', Because this will pass the entire string as a parameter, obviously this is not what the connector expects.

-Wl, Option
Set options OptionPass to connector. If OptionIf a comma is included in the content, you can split it into multiple options.
-U Symbol
The connector is considered canceled SymbolTo connect the library module to obtain the definition. You can use multiple' -U'Option, each with different symbols, so that the connector is transferred to the additional library module.
Directory Option)

The following options specify the search path to search for header files, library files, or compiler members:

-I Dir
Add to the search path list of the header file DirDirectory.
-I-
Any' -I-'Use EARLIER' -I'The specified search path applies only' # Include" File "'This situation; they cannot be used to search' # Include < File> 'Included header file.

If'-I'The specified search path is located'-I-'After the option, you can search for all 'in these paths'# Include'COMMAND. (generally-IThis is the option .)

Also ,'-I-'Option can prevent the current directory (where the current input file is stored) from becoming search'# Include"File"'The first choice. There is no way to overcome it'-I-'Specifies the option effect'-I.'Search for the directory. It is the current directory when the compiler is called. This is not the same as the default behavior of the Preprocessor, but the result is usually satisfactory.

`-I-'The use of standard system directories is not affected. Therefore ,'-I-'And'-Nostdinc'Is different.

-L Dir
In' -L'Added to the search path list of the option DirDirectory.
-B Prefix
This option specifies where to find executable files, library files, and the compiler's own data files.

The compiler driver needs to execute some of the following subprograms :'CPP','PC3'(Or C ++'Cc1plus'),'As'And'LD'.PrefixAs the prefix of the program to be executed, either include or not include'Machine/Version/'.

For the subroutine to run, the compiler driver first tries to add'-B'Prefix (if any). If no file is found or unspecified'-B'Option, the compiler will try two standard prefixes'/Usr/lib/GCC/'And'/Usr/local/lib/GCC-lib/'. If you still cannot find the required file, the compiler will'Path'Find the file name without any prefix in the path specified by the environment variable.

If necessary, run-time supports files'Libgcc.'Also'-B'Prefix' is within the search range. if not found, search for the two standard prefixes mentioned above. if the above method does not find this file, it will not be connected. in most cases ,'Libgcc.'Is not essential.

You can use environment variablesGcc_exec_prefixObtain the approximate effect. If this variable is defined, its value is prefixed as described above. If'-B'Option andGcc_exec_prefixVariable, the compiler first uses'-B'Option before trying the environment variable value.

Warning Option)

Warning refers to the diagnostic information for the program structure. The program may not have errors but risks or errors.

The following options control the number and type of warnings generated by gnu cc:

-Fsyntax-only
Check for syntax errors in the program, but no output information is generated.
-W
Disable all warning information.
-Wno-Import
Disable all # ImportWarning Information.
-Pedantic
Enable all warning diagnostics that are fully compliant with the ansi c standard; reject programs that use banned syntax extensions.

Whether this option is available, programs that conform to the ansi c standard should be correctly compiled (although few programs require'-ANSI'Option ). however, without this option, some GNU extensions and traditional c features are also supported. you can use this option to reject these programs. there is no reason to use this option. He only exists to satisfy some nerdy (pedant ).

For the alternative keyword (they use'__'Start and end )'-Pedantic'No warning information is generated. Pedantic does not warn_ Extension __The following expression. However, this escape measure should only be used in the system header file, which should be avoided by the application.

-Pedantic-Errors
This option and' -Pedantic'Similar, but an error is displayed instead of a warning.
-W
Additional warning information is displayed for the following events:
*
Nonvolatile automatic variable may be called LongjmpChanges occurred. These warnings only occur during compilation optimization.

The compiler only knowsSetjmpHe cannot know where to callLongjmpIn fact, a signal processing routine can call it anywhere in the program. The result is that even if the program has no problems, you may receive a warning, because it cannot be called in a where the problem may occur.Longjmp.

*
A function that can return a value or does not return a value (the function body without the end is regarded as not returning a function value). For example, the following function will cause this warning:

foo (a)
{
if (a > 0)
return a;
}


Since gnu cc does not know that some functions will never return (containAbortAndLongjmp), So there may be false warnings.

*
The expression statement or the left side of the comma expression does not have a function (side effect). To prevent this warning, you should forcibly convert unused expressions to the void type. For example, such expressions' X [I, j]'Will cause a warning, while' X [(void) I, j]'No.
*
Use' >'Or' <=.

-Wimplicit-int
The warning is not declared for the specified type.
-Wimplicit-function-Declaration
Warning the function used before declaration.
-Wimplicit
Same as-wimplicit-int and-wimplicit-function-declaration.
-Wmain
If MainWhen a function is declared or defined as a strange type, the compiler sends a warning. In typical cases, this function is used for external connections and returns IntNumeric value. No parameter is required or two parameters are specified.
-Wreturn-type
If the function defines the return type, the default type is IntType, the compiler will issue a warning and warn those without the return value ReturnStatement, if the function they belong to is not VoidType.
-Wunused
If a local variable is not used except declaration, or a static function is declared but not defined, or the operation result of a statement is obviously not used, the compiler will issue a warning.
-Wswitch
If SwitchThe statement parameter belongs to the enumeration type, but does not have the corresponding CaseThe compiler issues a warning when the statement uses enumeration elements .( DefaultThe statement can prevent this warning.) If it is out of the enumerated range CaseStatement also causes this warning.
-Wcomment
If the comment start sequence' /*'The compiler sends a warning when it appears in the annotation.
-Wtrigraphs
Warning any trigraph that appears (assuming they are allowed ).
-Wformat
Check PrintfAnd ScanfAnd other functions to confirm that the parameter types and format strings are consistent.
-Wchar-subscripts
Warning type is CharArray subscript. This is a common error. programmers often forget that char is signed on some machines.
-Wuninitialized
Use automatic variables before initialization.

These warnings may only occur during optimized compilation because they need data stream information. Data Stream information is estimated only when optimization is performed. If not specified'-O.

These warnings are only for variables waiting for register allocation. Therefore, they do not occur when declaredVolatileThe above variable does not occur in the obtained address variable, or the length is not equal to 1, 2, 4, 8 bytes. it also does not occur in the structure, union or array, even if they are in the register.

Note: If a variable calculates only one value that has never been used before, the calculation may not be warned because the calculation has been deleted by the data stream analysis before the warning is displayed.

These warnings are optional because gnu cc has not been smart enough to identify all the situations, and it knows that some code that looks wrong is actually correct. The following is an example:

{
int x;
switch (y)
{
case 1: x = 1;
break;
case 2: x = 4;
break;
case 3: x = 5;
}
foo (x);
}


IfYAlways 1, 2, or 3, thenXIt will always be initialized, but gnu cc does not know this. The following is another common case:

{
int save_y;
if (change_y) save_y = y, y = new_y;
...
if (change_y) y = save_y;
}


There is no error here, because onlySave_yTo use it.

Define all functions not returnedVolatileIt can avoid some plausible warnings.

-Wparentheses
In some cases, if parentheses are ignored, the compiler will issue a warning.
-Wtemplate-debugging
When a template is used in a C ++ program, if the debugging (debugging) does not take effect completely, the compiler will issue a warning (only for C ++ ).
-Wall
Combined with all of the above' -W'Option. We usually recommend that you avoid warning usage. We believe that using macros properly can easily avoid these usage.

The remaining'-W...'Option not included in'-Wall', Because we think that, if necessary, the structure of these programs warned by the compiler can be reasonably used in "clean" programs.

-Wtraditional
If some program structures are different from ansi c in traditional C, the compiler will issue a warning.
*
Macro parameters appear in the String constant of the macro body. Traditional C will replace the macro parameter, while ansi c regards it as part of the constant.
*
A function is declared as external in a block, but called only after the block ends.
*
SwitchThe statement's operand type is Long.
-Wshadow
Once a local variable shields another local variable, the compiler sends a warning.
-Wid-clash- Len
Once the two identified identifiers have the same LenThe compiler sends a warning. It can help you develop programs that will be compiled on some outdated compilers that endanger the brain.
-Wpointer-Arith
If any statement depends on the size of the function type or VoidType, the compiler sends a warning. gnu c for ease of Calculation Void *The pointer and function pointer define the size of these types as 1.
-Wcast-Qual
Once a pointer is forcibly converted to remove the type modifier, the compiler sends a warning. For example, if Const char *Forced conversion to common Char *The warning will appear.
-Wcast-align
Once a pointer type is forcibly converted, the compiler generates a warning when the alignment required by the target increases. for example, some machines can only access integers on the 2 or 4-byte boundary. Char *Forced conversion Int *Type, the compiler will issue a warning.
-Wwrite-strings
Specifies that the String constant type is Const char [ Length ]Therefore, copy the address to non- Const Char *Pointers will generate warnings. These warnings can help you find code that attempts to write string constants during compilation, but you must use them in the declaration and prototype very carefully. Const

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.