GCC a few of the most common options to do a brief description
GCC [-c|-s|-e] [-std=standard]
[-G] [-PG] [-olevel]
[-wwarn ...] [-pedantic]
[-idir ...] [-ldir ...]
[-dmacro[=defn] ...] [-umacro]
[-foption ...] [-mmachine-option ...]
[-o outfile] infile ...
-C compiles to the target file, only generates an object file, generates an. o file, and does not connect to the library.
The-o outfile generates the destination file, and if this option is not taken, the a.out is generated
-S compiled as assembly code
-e preprocessing. Code after preprocessing will be sent to standard output
-G to generate debugging information, or GDB will not be able to debug
-static does not use dynamic connection libraries, the dynamic library is generally directly integrated into the program,
Become part of the program, so the generated code is larger
-share uses dynamic libraries, so the code is relatively small and the program will not run when the dynamic library file does not exist.
-fpic generate independent code, and path-independent, generally with-share use.
-wall, turn on all warnings.
-dname=definition ... There are two ways to define macros on the command line, either-dname or-dname=definition. The purpose of setting a macro definition on the command line is primarily to set some switches when you are debugging, and then close or turn them on when you release them. Of course the macro definition is also used to selectively compile the code. There are other functions as well.
-llibrary searches the library at the time of the connection. Libraries are archieve files whose members are target files. If there is a file reference library,library the command line position should be after that file, so The lower the bottom of the library should be placed in the back. For example, if you are connecting to the PCAP library, you need to compile the source file using-lpcap.
-ldir ... Add dir to the search path for the library file, and GCC will search for dir before searching the standard library files.
-pthread adds support for multithreading through the Pthreads library, which sets the flag for preprocessing and connections. Pthread is a POSIX-specified standard line threading.
-std=standard set the standard that is used for C language, such as-std=c99 that the compiler follows the C99 standard. This option is less used. And sometimes you get confused.
-mmachine-option ... Specifies the platform you are using.
(Note: The above is just the tip of the iceberg of GCC, and more of it has to go to the GCC Manual.) In addition, the option marked with an ellipsis indicates that there can be multiple
Gccparameter Detailed and example
Introduced
GCC and g++ are GNU C & C + + compilers, respectively
gcc/g++ It takes 4 steps to perform the compile work
1. Preprocessing, generating. I files [preprocessor CPP]
2. The preprocessed file will not be converted into assembly language, generating files. s[compiler Egcs]
3. Files with assembly into object code (machine code) generate. o file [assembler as]
4. Connect target code, generate executable program [linker LD]
[Detailed parameters]
-X language filename
Sets the language in which the file is used, invalidates the suffix name, and is valid for more than one later. That's the root.
According to the Convention C language suffix name is. c, and C + + suffix name is. C or. cpp, if
You are very personality, decide your C code file suffix name is. Pig Haha, then you need to use this
parameter, which works on the file names that follow, unless the next argument
of use.
Can I use any of the following parameters?
' C ', ' objective-c ', ' c-header ', ' C + + ', ' cpp-output ',
' Assembler ', and ' assembler-with-cpp '.
See English, you should be able to understand.
Example usage:
Gcc-x C Hello.pig
-X None filename
Turn off the last option, which means that GCC automatically recognizes the file type according to the filename 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 obj files
Example usage:
Gcc-c hello.c
He will generate. O's obj file
-S
Activating preprocessing and compiling only means compiling the file into assembly code.
Example usage
Gcc-s hello.c
He will generate the assembly code for. S, and you can use a text editor to see
-E
Activate preprocessing only, this does not generate a file, you need to redirect it to an output file
Surface.
Example usage:
GCC-E hello.c > Pianoapan.txt
GCC-E hello.c | More
Look slowly, a Hello word also wants to work with 800 lines of code
-O
Set the target name, by default, GCC compiled the file is a.out, it is difficult to listen, if
You and I have the same feeling, get rid of it, haha
Example usage
Gcc-o hello.exe hello.c (oh, Windows used to)
Gcc-o hello.asm-s hello.c
-pipe
Using a pipeline instead of a temporary file in a compilation, there may be some questions when using non-GNU assembler tools
Problem
Gcc-pipe-o Hello.exe hello.c
-ansi
Turn off the features in GNU C that are incompatible with ANSI C and activate the proprietary features of ANSI C (including the prohibition of a
Some ASM inline typeof keywords, as well as preprocessing macros such as Unix,vax,
-fno-asm
This option implements part of the functionality of the ANSI option, which prohibits the use of asm,inline and typeof as
Key words.
-fno-strict-prototype
Only works on g++, using this option, g++ will not have an explicit function for functions that do not take arguments
The number and type description of the arguments, not without arguments.
and GCC regardless of whether or not to use this parameter, will have no parameters with the function, that the city does not explicitly say
Type of Ming
-fthis-is-varialble
is to the traditional C + +, you can use this when the general variable use.
-fcond-mismatch
Allow the second and third parameter types of the conditional expression to not match, and the value of the expression will be a void type
-funsigned-char
-fno-signed-char
-fsigned-char
-fno-unsigned-char
These four parameters are set to the char type, which determines that the char type is set to unsigned char (former
two parameters) or signed char (latter two parameters)
-include file
Contains a code that, in short, is a file that requires another file to be
With it, the function is equivalent to using #include<filename> in your code.
Example usage:
GCC Hello.c-include/root/pianopan.h
-imacros file
Expands the file's macro to the gcc/g++ input file, and the macro definition itself does not appear in the input file
In
-dmacro
Equivalent to the #define macro in C language
-dmacro=defn
Equivalent to the #define MACRO=DEFN in C language
-umacro
Equivalent to the #undef macro in C language
-undef
Cancel the definition of any nonstandard macro
-idir
When you are using #include "file", gcc/g++ will first look up your head in the current directory
File, if not found, he went back to the default header file directory to find, if using-I developed the directory, he
Go back to the directory you made and look for it in the usual order.
For the directory lookup that the #include<file>,gcc/g++ will make to-I, I can't find it, and then I will go to the department
The default header file directory lookup of the EC
-i-
is to cancel the function of the previous parameter, so it is generally used after-idir
-idirafter dir
Find failure in the directory of-I, and refer to this directory to find.
-iprefix Prefix
-iwithprefix dir
Generally used together, when-I directory lookup failed, will go to the Prefix+dir under Search
-nostdinc
Make the compiler no longer system default header file directory inside the change file, general and-I joint use, clear
Position of the qualifying header file
-nostdin C + +
The rule does not search in the standard path specified by g++, but still searches in other paths. This option creates
libg++ Library Use
-C
In the preprocessing, do not delete the annotation information, general and e-use, and sometimes analysis of the program, with this very
Convenient for
-M
Generates the information associated with the file. Contains all source code that the target file relies on
You can use gcc-m hello.c to test it, it's very simple.
-mm
Same as the one above, but it ignores dependencies caused by #include<file>.
-md
Same as-M, but the output will be imported into the. d file
-mmd
Same as-mm, but the output is imported into the. d file.
-wa,option
This option passes option to the assembler; if there is a comma between option, option is divided into multiple selections
Item and then pass it to the Assembly
-wl.option
This option passes option to the connector, and if there is a comma between option, option is split into multiple selections
Item, and then pass it to the connecting program.
-llibrary
Create a library to use when compiling
Example usage
Gcc-lcurses hello.c
Compiling programs using the Ncurses library
-ldir
When compiling, search the path of the library. such as your own library, you can use it to create a directory, or
The compiler will only look in directories in the standard library. This dir is the name of the directory.
-o0
-o1
-o2
-o3
4 levels of compiler optimization options,-o0 means no optimizations,-o1 defaults,-O3 optimization level most
High
-G
Just the compiler, when compiling, the production bar is information.
-gstabs
This option claims debugging information in the stabs format, but does not include GDB debugging information.
-gstabs+
This option claims debugging information in the stabs format and contains additional debugging information that is available only to GDB.
-ggdb
This option will generate the debug information that GDB can use as much as possible.
-static
This option disables the use of dynamic libraries, so the things that are compiled are generally large and do not require anything <