GCC g ++ common compilation options

Source: Internet
Author: User
Gcc
G ++ common compilation options
GCC and G ++ common compilation options in Linux

-X language filename
 
Set the language used by the file to make the suffix invalid and valid for later versions. that is, according to the Conventions, the C language suffix is. c, and C ++'s suffix is. C or. CPP. If you have a personality, the suffix of your C code file is. pig
Haha, you need to use this parameter. This parameter applies to all the file names after it, unless it is used by the next parameter. The following parameters are available:
'C ',
'Objective-C', 'c-header', 'c ++ ', 'cpp-output', 'authorizer', and 'a

Ssembler-with-CPP '.
You can understand English.
 
Example: CD ..
Gcc
-X C hello. Pig

-X none filename
Turn off the previous option, that is, let GCC automatically identify the file type based on the file name suffix
Example usage:

Gcc-x C hello. Pig-x none hello2.c
  
-C

Only activate preprocessing, compilation, and assembly, that is, he only makes the program into an OBJ file.
Example usage:
Gcc-C hello. c

It will generate the. o obj file
-S
Only activating preprocessing and compilation means compiling a file into assembly code.
Example usage
Gcc
-S hello. c
It will generate the. s assembly code. You can view it in a text editor.
-E

Only activate preprocessing. If this file is not generated, You need to redirect it to an output file.
Example usage:
Gcc-e hello. c>
Pianoapan.txt
Gcc-e hello. c | more
Take a look. A Hello word can be preprocessed into 800 lines of code.

-O
Set the target name. By default, the GCC compiled file is a. Out, which is hard to hear. If you feel the same way with me, change it. Haha
Example usage

Gcc-O hello.exe hello. C (Oh, Windows is used to it)
Gcc-O hello. ASM-s hello. c

-Pipe
Using pipelines instead of temporary files during compilation may cause some problems when using non-GNU compilation tools.
Gcc-pipe-O hello.exe
Hello. c
-ANSI
Disable features incompatible with ansi c in gnu c and activate the proprietary features of ansi c (including disabling some ASM inline
Typeof keywords and preprocessing macros such as UNIX and VAX

/*
************************************ ****************

-Fno-ASM
This option is part of the feature that implements the ANSI option. It prohibits the use of ASM, inline, and typeof as keywords.
    
-Fno-strict-Prototype

It only works for G ++. With this option, G ++ does not explicitly describe the number and type of parameters for functions without parameters, instead of having no parameters.

Whether this parameter is used or not, GCC considers that there is no explicitly stated type for a function without parameters.

  
-Fthis-is-varialble

Is to align with the traditional C ++, you can use this when the general variable is used.
  
-Fcond-Mismatch

The second and third parameter types of conditional expressions do not match. The expression value is of the void type.
  
-Funsigned-Char

-Fno-signed-Char
-Fsigned-Char
-Fno-Unsigned-Char

These four parameters are used to set the char type and decide to set the char type to unsigned char (the first two parameters
Number) or signed
Char (the last two parameters)

************************************* ********/

-Include File

To put it simply, when a file needs another file, you can use it
The function is equivalent to using # I
Nclude <FILENAME>
Example usage:
GCC hello. C-include/root/pianopan. h

  
-Imacros File
Extend the macro of the file to GCC/G ++The macro definition does not appear in the input file.
  

-Dmacro
Equivalent to # define macro in C
  
-Dmacro = defn

Equivalent to # define macro = defn in C
  
-Umacro
Equivalent to # UNDEF macro in C

-UNDEF
Cancel definition of any non-standard macros
  
-Idir
# I
Nclude "file", GCC/G ++You will first find the header file in the current directory, as shown in figure

If it is not found, he will return to the default header file directory. If-I is used to specify the directory
Go back to the directory you created, and then find it in the regular order.
For # I
Nclude <File>, GCC/G ++It will go to the directory specified by-I and cannot be found. Then it will go to the system's missing

Saved header file directory search
  
-I-
Is to cancel the function of the previous parameter, so it is generally used after-Idir
  

-Idirafter dir
An error occurred while searching in the-I directory.
  
-Iprefix prefix

-Iwithprefix dir
Generally, if-I Directory Search fails, it will be searched under prefix + dir
  

-Nostdinc
Enable the compiler to no longer find the header file in the system's default header file directory. It is generally used in conjunction with-I and explicitly limits the header.
File Location
  

-Nostdin C ++
Not SpecifiedG ++The specified standard path is searched, but it is still searched in other paths.OptionCreating a libg ++ Library
Use
  
-C

During pre-processing, do not delete the annotation information, which is generally used with-E. Sometimes the analysis program is very convenient to use.


-M
Generate file association information. You can use GCC to include all source code that the target file depends on.
-M hello. c
It's easy to test.
  
-Mm
It is the same as the one above, but it will ignore
Dependency caused by nclude <File>.
  
-MD
It is the same as-M, but the output will be imported into the. d file.
  

-MMD
It is the same as-mm, but the output will be imported into the. d file.
  
-Wa, Option
ThisOptionPass the option to the assembler. If there is a comma in the option, the option is divided into multipleOption, However
And then pass it to the assembler.
  

-WL. Option
ThisOptionThe option is passed to the connection program. If there is a comma in the option, the option is divided into multipleOption, However
And then pass it to the connected program.
  

-Llibrary
Library Used during compilation
Example usage
Gcc-lcurses hello. c

Compile the program using the ncurses Library
  
-Ldir
Specify the path of the database to be searched during compilation. For example, you can use your own library to create a directory. Otherwise

The compiler will only find it in the standard library directory. This DIR is the directory name.
  
-O0
-O1
-O2
-O3

Compiler OptimizationOption-O0 indicates no optimization,-O1 indicates the default value, and-O3 indicates the highest optimization level.

    
-G
Only the compiler generates debugging information during compilation.
  
-Maid
ThisOptionIt claims debugging information in stabs format, but does not include GDB debugging information.

  
-Gstabs +
ThisOptionThe debugging information is claimed in stabs format and contains additional debugging information for GDB only.

  
-Ggdb
ThisOptionGenerate debugging information that can be used by GDB as much as possible.

-Static
ThisOptionDynamic libraries are not allowed. Therefore, compilation is usually very large and does not require any

The dynamic connection library can be run.
-Share
ThisOptionThe dynamic library will be used as much as possible, so the file generation is small, but the system must use the dynamic library.

-Traditional
Try to make the compiler support the traditional C Language Features

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.