[Go] gcc,g++ Common compilation options in Linux

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_5ff2a8a201011ro8.html

gcc/g++ requires 4 steps to perform the compilation

1. Preprocessing, generating. i files [using the-e parameter]

2. The preprocessed file is not converted to assembly language, and the file is generated. s[using the-s parameter]

3. There is a compilation into the target code (machine code) to generate. o files [using the-C parameter]

4. Connect the target code, generate the executable program [using the-o parameter]

-X language filename
Set the language used by the file, so that the suffix name is invalid for later multiple valid. That is, according to the Convention, the C language suffix name is. c, and the C + + suffix name is. C or. cpp, if you are very personality, decide the suffix name of your C code file is. Pig haha, then you'll use this parameter, which will work for the file name behind him unless the next parameter is used. The parameters that can be used are the following:
' C ', ' objective-c ', ' c-header ', ' C + + ', ' cpp-output ', ' assembler ', and ' a
Ssembler-with-cpp '.
It should be understandable to see English.

Example usage: CD.
Gcc-x C Hello.pig
-X None filename
Turn off the previous option, which is to have GCC automatically identify file types based on the filename suffix
Example usage:
Gcc-x c Hello.pig-x None hello2.c
  
-C
Only activates preprocessing, compilation, and assembly, that is, he only makes the program obj file
Example usage:
Gcc-c hello.c
He will generate the. O obj file
-S
Only pre-processing and compilation are activated, which means compiling the files into assembly code.
Example usage
Gcc-s hello.c
He will generate the assembly code for. S, which you can view with a text editor
-E
Only activate preprocessing, this does not generate files, you need to redirect him to an output file inside.
Example usage:
GCC-E hello.c > Pianoapan.txt
GCC-E hello.c | More
Look slowly, a Hello Word will be preprocessed into 800 lines of code
-O
Set the target name, by default, GCC compiled files are a.out, very bad, if you and I have the same feeling, to change 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 the temporary files in the compilation, there may be some problems when using non-GNU assembler tools
Gcc-pipe-o Hello.exe hello.c
-ansi
Turn off the incompatible features in GNU C and ANSI C, activating the proprietary features of ANSI C (including the prohibition of some ASM inlinetypeof keywords, and unix,vax such as preprocessing macros
  
-include file
Contains a code that, simply, makes it easier for a file to be used when another file is needed.
function is equivalent to using #i in code nclude
Example usage:
GCC Hello.c-include/root/pianopan.h
  
-imacros file
To extend the file's macro to the gcc/g++ input file, the macro definition itself does not show up in the current input file
  
-dmacro
Equivalent to # define macro in C language
  
-dmacro=defn
The equivalent of # define MACRO=DEFN in the C language
  
-umacro
Equivalent to #undef macro in C language
-undef
Cancel the definition of all non-standard macros
  
-idir
When you use #i nclude "file", gcc/g++ will first find the header file you made in the current directory, such as
The result is not found, he returns to the default header file directory to find, if using-I developed a directory, he
Go back to the directory you have set up, and then follow the usual sequence to find it.
For #i nclude,gcc/g++ will go to-I developed directory lookup, check not found, and then to the system of missing
Province's header file directory lookup
  
-i-
is to cancel the function of the previous parameter, so it is generally used after-idir
  
-idirafter dir
Look for a failure in the-I directory, refer to this directory to find.
  
-iprefix Prefix
-iwithprefix dir
Generally used together, when-I directory lookup failed, will be found under Prefix+dir
  
-nostdinc
Make the compiler no longer the system default header file directory inside the your change file, general and-I joint use, explicitly qualified header
The location of the file
  
-nostdin C + +
The rule does not search in the standard path specified by g++, but is still searched in other paths. This option is in the Genesis libg++ Library
Use
  
-C
In the preprocessing, do not delete the comment information, General and e-use, and sometimes analytical program, with this very convenient
-M
Generates information about the file association. Contains all the original code that the target file depends on you can use Gcc-m hello.c
To test it, it's very simple.
  
-mm
The same as the one above, but he will ignore the dependency caused by #i nclude.
  
-md
Same as-M, but the output will be imported into the. d file
  
-mmd
Same as-mm, but the output will be imported into the. d file.
  
-wa,option
This option passes option to the assembler, and if option has commas in the middle, option is divided into multiple options,
After passing it to the Assembly program
  
-wl.option
This option passes option to the connector, and if option has commas in the middle, option is divided into multiple options,
After passing it to the connecting program.
  
-llibrary
Create a library to use when compiling
Example usage
Gcc-lcurses hello.c
Compiling the program using the Ncurses Library
  
-ldir
When compiling, search for the path to the library. such as your own library, you can use him to make a directory, or
The compiler will only look in the catalog of the standard library. This dir is the name of the directory.
  
-o0
-o1
-o2
-o3
4 levels of the compiler's tuning options,-o0 for no optimizations,-o1 defaults,-o3 optimization level highest
    
-G
Just the compiler, at compile time, generates debug information.
  
-gstabs
This option claims debug information in stabs format, but does not include GDB debugging information.
  
-gstabs+
This option claims debug information in the stabs format and contains additional debugging information that is intended for use by GDB only.
  
-ggdb
This option will generate the debug information that GDB can use whenever possible.
-static
This option disables the use of dynamic libraries, so the compiled items are generally very large and do not have to be anything
Dynamic Connection library, you can run it.
-shared
This option will use the dynamic library as much as possible, so the resulting file is smaller, but requires the system to be a dynamic library.
-traditional
Trying to get the compiler to support traditional C language features
-wall
Show all warning messages (warning all)

[Go] gcc,g++ Common compilation options in Linux

Related Article

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.