[version]
-0.13
[statement]
This document is my note about GCC parameters. I miss the DOS era, I use small books, record all DOS.
The parameters of the command. Haha, the following things may not be very comprehensive, I will refer to a lot of books, and the help of GCC.
The reason is that it is possible that I haven't seen this parameter yet. Another reason is that I may not use it.
However, I will slowly make up. Haha
If you want to turn in this article, please keep my email (pianopan@beeship.com) and the article
Nosh.
[Introduction]
GCC and G is a GNU's C & C compiler
GCC / G requires 4 steps when performing compilation
1. Preprocessing, generated .i file [Preprocessor CPP]
2. Put the pre-processed files into assembly language, generate files .s [compiler EGCS]
3. Compiled change to the target code (machine code) generation .o file [assembler as]
4. Connect the target code to generate an executable [linker LD]
[Parameter Detailed]
-x Language FileName
Set the language used by the file, make the rejected name invalid, which is valid for future. That is
According to the surfix name of the convention C language, C suffer name is .c or .cpp, if
You are very personal, decide that your C code file is the name .pig haha, then you will use this
Parameters, this parameter works on the file name behind him, unless the next parameter
usage of.
Can you use the parameters?
`c ',` Objective-c', `c-header ',` C ', `cpp-output ',
`assembler ', and` assembler-with-cpp'.
Seeing English and should be understood.
Example usage:
GCC -X C Hello.pig
-x none filename
Turn off the previous option, that is, let GCC automatically identify file types according to the file name suffix.
Example usage:
gcc-x c hello.pig -x none hello2.c
-C
Only activate pretreatment, compile, and compile, that is, he only makes the program into an OBJ file.
Example usage:
GCC -C Hello.c
He will generate .o OBJ file
-S
Only the pretreatment and compilation are true to compile files into assembly code.
Example usage
GCC -S Hello.c
He will generate .S assembly code, you can use the text editor to see
-E
Only activate preprocessing, this does not generate files, you need to redirect it into an output file
surface.
Example usage:
GCC-E Hello.c> Pianoapan.txt
GCC-E Hello.c | More
Slowly look, a Hello Word also has to process the code to be 800 lines.
-o
Develop a target name, the default, the files compiled by the GCC are A.out, it is difficult to listen, if
You have the same feelings, 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
Use the pipeline instead of the temporary file, maybe some questions when using non-GNU assembly tools
question
GCC -PIPE -O Hello.exe Hello.c
-ansi
Turn off the characteristics of incompatibility with ANSI C in GNU C, activate the proprietary characteristics of ANSI C (including disabling one
Some ASM inline typeof keywords, and Unix, VAX and other pre-processing macros,
-FNO-ASM
This option implements a part of the function of the ANSI option, which is forbidden to use ASM, Inline and TypeOf as
Keyword.
-fno-strict-prototype
Only the role of G , use this option, G will do a function without parameters, it is not explicitly
The number and type of parameters, instead of no parameters. And the GCC will have a function without the parameters regardless of whether it is used, regardless of the city.
Type
-fthis-is-varialble
Just look at traditional C , you can use this as a general variable.
-fcond-mismatch
Allow conditional expressions of the second and third parameter types that do not match, the value of the expression will be the Void type
-funsigned-char
-fno-signed-char
-fsigned-char
-fno-unsigned-char
These four parameters are set to the char type and decide to set the char type to unsigned char.
Two parameters) or signed char (after two parameters)
-include file
Contains a code, simply, it is possible to use a file, you can need another file.
Use it, the function is equivalent to using #include in the code.
Example usage:
GCC Hello.c -inClude /Root/pianopan.h
-imacros file
The macro of the file file is extended to the GCC / G input file, the macro definition itself does not appear in the input file
in
-Dmacro
Equivalent to C language #define macro
-Dmacro = DEFN
Equivalent to C language #define macro = defn
-Umacro
Quite in the C language #undef macro
-undef
Cancel the definition of any non-standard macro
-IDIR
When you use a #include "file", GCC / G will look for the heads you make in the current directory.
Document, if not found, he returns to the default header file directory, if you use -i to make a directory, he
I will look for the directory you have developed, and then look at the regular order.
For #include
GCC / G will look for the directory set by -i, find can't look up, and then
Default header file directory lookup
-I-
It is the function of canceling the previous parameter, so it is generally used after -idir.
-idirafter Dir
Find failed in the -i directory, telling this directory to find it.
-IPRefix Prefix
-iwithPRefix Dir
Generally used, when the -i directory looks failed, look for prefix dir
-nostdinc
Make the compiler no longer the system default header file directory to find the header, generally and -i joint use, clear
Limited the position of the header file
-NostDin C
The standard roads not specified in G are searched in other paths, but they are created in other paths.
Libg library
-C
When pretreatment, do not delete the comment information, generally and -e use, sometimes analyze the program, use this very
convenient
-M
Generate the information associated with files. All source code depends on the target file
You can use gcc -m hello.c to test it, it is very simple.
-Mm
The same as the above, but it will ignore from #include
Resulting dependency.
-Md
Same as -m, but output will be imported into .d.
-Mmd
Same as -mm, but output will be imported into .d.
-WA, Option
This option passes the Option to the assembler; if there is a comma in the Option, you divide the option into multiple elections.
Item, then pass to the assembler
-Wl.option
This option passes the Option to the connection program; if there is a comma in the Option, you divide the option into multiple elections.
Item, and then pass to the connection program.
-llibrary
Formulate the library when compiled
Example usage
gcc -lcurses Hello.c
Compile using NCURSES library
-Ldir
When developing compilation, search the path of the library. For example, your own library, you can use it to formulate a directory, otherwise
The compiler will only find it in the directory of the standard library. This DIR is the name of the directory.
-O0
-O1
-O2
-O3
4 levels of the optimization options for the compiler, -O0 indicate that there is no optimization, -o1 is the default value, the -O3 optimization level is highest
-g
Just the compiler, when compiling, the generating strip is information.
-gstabs
This option claims to debug information in a Stabs format, but does not include GDB debugging information.
-gstabs
This option claims to debug information in a Stabs format and includes additional debugging information for GDB.
-ggdb
This option will generate the debugging information of GDB as much as possible.
-static
This option will prohibit the use of dynamic libraries, so it is generally very large, no need.
Dynamic connection library can run.
-Share
This option will try to use dynamic libraries, so generate files are relatively small, but the system needs to be generated by dynamic libraries.
-traditional
Try to make the compiler support the traditional C language characteristics
[Reference]
-Linux / UNIX Advanced Programming
Zhongke Hongqi Software Technology Co., Ltd. Edited. Tsinghua University Press Publishing
-Gcc man Page
[Changelog]
-2002-08-10
Ver 0.1 releases the original document
-2002-08-11
Ver 0.11 Modify Document Format
-2002-08-12
Ver 0.12 joins the parameters for static libraries, dynamic libraries
-2002-08-16
Ver 0.16 adds 4 phases of GCC compilation