Introduction to gcc

Source: Internet
Author: User
Document directory
  • -M
  • -MM
  • -S
  • -E
  • -C
  • -Include file
  • -Dmacro is equivalent to # define macro in C.
  • -Dmacro = defn is equivalent to # define macro = defn in C.
  • -Umacro is equivalent to # undef macro in C.
  • -Undef undefines any non-standard macros
  • -X language filename
  • -X none filename
  • -Pipe
  • -Ansi
  • -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.
  • -Fcond-mismatch: the second and third parameter types of conditional expressions are not matched, and the expression value is of the void type.
  • -Funsigned-char-fno-signed-char-fsigned-char-fno-unsigned-char
  • -Imacros file extends the macro of the file to the input file of gcc/g ++. The macro definition does not appear in the input file.
  • -I-is to cancel the function of the previous parameter, so it is generally used after-Idir
  • -The idirafter dir fails to be searched in the-I directory.
  • -Iprefix prefix-iwithprefix dir is generally used together. When the-I directory fails to be searched, it will be searched under prefix + dir.
  • -Nostdinc
  • -MD and-M are the same, but the output will be imported into the. d file.
  • -MMD and-MM are the same, but the output will be imported into the. d file.
  • -Wa, option
  • -Wl. option
  • -Maid
  • -Gstabs +
  • -Ggdb
  • -Static
  • -Share
  • -Traditional

Gcc is the gnu c compiler. It takes a total of four steps for gcc to compile:


1. Preprocessing: generate a. I file [Preprocessor]
2. Do not convert the pre-processed files into assembly languages to generate the file. s [compiler egcs]
3. a. o file is generated by means of compilation into the target code (machine code) [assembler as]

4. Connect the target code to generate an executable program [linker ld]

Slave --------------------------------------------------------------------------------------------------------------------------------

[Common parameters]-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
-O

Specify the target name. By default, the gcc compiled file is a. out,
Example usage:
Gcc-o hello.exe hello. c (windows)
Gcc-o hello. asm-S hello. c
-00-01-02-03
The compiler has four levels of optimization options.-00 indicates no optimization,-01 indicates the default value, and-03 indicates the highest optimization level.
-G

Only the compiler generates debugging information during compilation.
-M

Generate file association information, including all source code on which the target file depends.
You can use gcc-M hello. c to test it.
-MM

It is the same as the one above, but it will ignore the dependency caused by # include <file>.
-S

Only activating preprocessing and compilation means compiling a file into assembly code.
Example: gcc-S hello. c
It will generate the. s assembly code, which can be viewed in a text editor.
-E

Only activate preprocessing. This does not generate a file. You need to redirect it to an output file.
Example usage:
Gcc-E hello. c> pianoapan.txt
Gcc-E hello. c | more
Let's take a look. A hello word should also process hundreds of lines of code.
-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.
[Other parameters]-include file

Include a code. Simply put, a file can be set with another file. The function is equivalent to using # include <filename> in the code.
Example: gcc hello. c-include/root/pianopan. h
-Dmacro is equivalent to # define macro-Dmacro = defn in C. It is equivalent to # define macro = defn-Umacro in C. It is equivalent to # undef macro-undef in C to cancel definition of any non-standard macro-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 decide the suffix of the C code file is. pig, you need to use this parameter. This parameter applies to all the file names after it, unless it is used by the next parameter.
Example: 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: gcc-x c hello. pig-x none hello2.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 the incompatible features of ansi c in gnu c and activate the proprietary features of ansi c (including prohibiting 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. -Fcond-mismatch: the second and third parameter types of conditional expressions do not match, the expression value is void-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) or signed char (the last two parameters)
-Imacros file extends the macro of the file to the input file of gcc/g ++. The macro definition itself does not appear in the input file-Idir

When you use # include "file", gcc/g ++ first searches for the header file in the current directory. If not, he returns to the default header file directory. If-I is used to create a directory, he first searches for the directory you have set and then searches for it in the general order. for # include <file>, gcc/g ++ will go to the directory specified by-I and cannot find it. Then, it will go to the default header file directory of the system.
-I-is to cancel the function of the previous parameter. Therefore, you may fail to use-idirafter dir in the-I directory after-Idir. -iprefix prefix-iwithprefix dir is generally used together. When-I Directory Search fails, it will find-nostdinc under prefix + dir.

Make the compiler no longer look for the header file in the system's default header file directory. It is generally used in conjunction with-I to specify the position of the header file.
-MD and-M are the same, but the output will be imported to the. d file-MMD and-MM are the same, but the output will be imported to the. d file-Wa, option

This option is passed to the assembler; if there is a comma in the option, the option is divided into multiple options, and then passed to the assembler
-Wl. option

This option is passed to the connection program. If there is a comma in the option, the option is divided into multiple options and then passed to the connected program.
-The llibrary is used for compiling.

Example: gcc-lcurses hello. c. Use the ncurses library to compile the program

-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 the directory in the standard library. This dir is the directory name.
-Maid

This option claims debugging information in stabs format, but does not include gdb debugging information.

-Gstabs +

This option claims debugging information in stabs format and contains additional debugging information for gdb only.

-Ggdb

This option will generate debugging information that can be used by gdb as much as possible.

-Static

This option will prohibit the use of dynamic libraries. Therefore, compiled items are generally large and can be run without any dynamic Connection Library.
-Share

This option will try to use the dynamic library, so the generated file is small, but the system needs to use the dynamic library.

-Traditional

Try to make the compiler support the traditional C Language Features

Transfer from Baidu Library http://wenku.baidu.com/view/64853f37a32d7375a41780a3.html

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.