GCC compilation options

Source: Internet
Author: User

Version]-0.13
[Statement]
This document is my note on gcc parameters. I miss the time when I used a notebook to record the parameters of any dos command. haha, the following things may not be very comprehensive. I have referenced a lot of books and gcc help. the reason is that I may not see this parameter yet. Another reason is that I may not use this parameter, but I will make it up slowly. haha if you want to transfer in this article please keep my email (pianopan@beeship.com) and the comprehensive article.
[Introduction]
Gcc and g ++ are the gnu c & c ++ compiler gcc/g ++. A total of four steps are required during compilation.
1. Pre-processing: generate a. I document [pre-processor cpp]
2. Do not convert the pre-processed documents to the assembly language to generate the document. s [compiler egcs]
3. a. o file generated by compilation into the target code (machine code) [assembler as]
4. Connect the target code to generate the executable program [linker ld]

[Parameter Details]
-X language filename
Set the language used by the document 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 document is. pig Haha, you need to use this parameter. This parameter applies to the document names after it, unless it is used by the next parameter.
Can I use the following parameters?
'C', 'Objective-C', 'c-header', 'c ++ ', 'cpp-output', 'Explorer ', and 'author er-with-cpp '.
You should be able to understand English.
Example usage:
Gcc-x c hello. pig

-X none filename
Turn off the previous option, that is, let gcc automatically identify the document type based on the document 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 document.
Example usage:
Gcc-c hello. c
He will generate the. o obj document

-S
Only activating preprocessing and compilation means compiling a document into assembly code.
Example usage
Gcc-S hello. c
It will generate the. s assembly code, which you can view in a text editor

-E
Only activate preprocessing. If this document is not generated, You need to redirect it to an output document.
Example usage:
Gcc-E hello. c> pianoapan.txt
Gcc-E hello. c | more
Let's take a look. A hello word also needs to process 800 lines of code.

-O
Custom target name. By default, the gcc-compiled document is a. out, which is hard to hear. If you share the same feelings with me, get rid of him. 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 compiling temporary documents may cause some problems when using non-gnu compilation tools.
Gcc-pipe-o hello.exe hello. c

-Ansi
Disable the incompatible features of gnu c and ansi c, and activate the proprietary features of ansi c (including forbidding some asm inline typeof keywords, along with 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 ++, 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 configure the char type and decide to set the char type to unsigned char (the first two parameters) or signed char (the last two parameters)

-Include file
Include a code. Simply put, a document can be set with another document. The function is equivalent to using # include <filename> in the code.
Example usage:
Gcc hello. c-include/root/pianopan. h

-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.

-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
When you use # include "file", gcc/g ++ first searches for the customized header document in the current directory. If not, he returns to the default header document directory. If-I is used to customize the directory
First, search for the customized directory, and then find it in the general order.
For # include <file>, gcc/g ++ will find the custom-I Directory, which is difficult to find. Then, it will be searched in the system's default header document directory.

-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
Make the compiler no longer look for the header document in the system's default header document directory. It is generally used in conjunction with-I to specify the position of the header document

-Nostdin C ++
The rule is not to be searched in the standard channels specified by g ++, but still in other paths. This option is used in the create libg ++ library.

-C
During pre-processing, comments are not deleted, which is generally used with-E. Sometimes, the analysis program is very convenient to use.

-M
Generate the information associated with the document. You can use gcc-M hello. c to test any source code that contains the target document.

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

-MD
It is the same as-M, but the output will be imported into the. d document.

-MMD
It is the same as-MM, but the output will be imported into the. d document.

-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.

-Llibrary
Library Used for custom Compilation
Example usage
Gcc-lcurses hello. c
Compile a program using the ncurses Library

-Ldir
The path of the database to be searched during compilation. For example, you can use your own library to customize directories. Otherwise
The compiler will only find it in the standard library directory. This dir is the directory name.

-O0
-O1
-O2
-O3
The compiler has four levels of optimization options.-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
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 disable the use of dynamic libraries. Therefore, the compiled items are usually large, and nothing is needed.
The dynamic connection library can be run.

-Share
This option will try to use the dynamic library, so the generated documents are relatively small, but the system needs to use the dynamic library.

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

[References]
-Linux/UNIX Advanced Programming
Edited by zhongke Hongqi Software Technology Co., Ltd. Published by Tsinghua University Press
-Gcc man page

[ChangeLog]
-2002-08-10
Ver 0.1 released the original document
-2002-08-11
Ver 0.11 modify document format
-2002-08-12
Server 0.12 adds parameters for static and dynamic libraries
-2002-08-16
Ver 0.16 adds four phases of gcc compilation commands

 

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.