The GCC compiler is usually followed by some options and file names. The basic usage of the GCC command is as follows:
GCC [Options] [filenames]
Option specifies how the compiler is compiled.
GCC options
GCC has 100 compilation options. Many of these options may never be used, but some of the main options are often used. Many gcc
The options include more than one character, so you must specify the respective characters for each option. For example, the following two commands are different:
Gcc-p-g test. c
Gcc-PG test. c
The First Command tells GCC to create profile information for the prof command during test. c compilation and add the debugging information to the executable file. The second command only tells gcc
Create profiling information for the GPROF command.
If no option is available, GCC generates an executable file named A. Out.
Use the-O compilation option to name the generated executable files with the specified file name. For example, compile a C program named count. c into an executable file named count,
Enter the following command:
Gcc-O count. c
-The C option tells GCC to compile only the source code as the target code. There is a. o extension in the target code file created by GCC.
The-s compilation option tells GCC to stop compilation after an assembly language file is generated for C code. The default extension of assembly language files generated by GCC is. S.
The-E Option indicates that the compiler only preprocess the input file. When this option is used, the pre-processor output is sent to the standard output instead of stored in the file.
When compiling C code with GCC, it will try to complete the compilation at least and make the compiled code easy to debug.
Easy debugging means that the compiled code is not optimized. When necessary, the compiler needs to optimize the code.
The-O option tells GCC to perform basic optimization on the source code. In most cases, these optimizations make program execution faster. -The O2 option tells GCC to generate code as small as possible and as fast as possible. -O2
Option will make the compilation speed slower than when using-o, but usually the generated code will be executed faster.
GCC supports several debugging and profiling options, commonly used-G and-PG.
The-G option tells GCC to generate debugging information that can be used by the GNU Debugger to debug your program. GCC provides a feature that is not available in many other C compilers. in GCC, you can
-G and-O (produce optimization code.
-The PG option tells GCC to add additional code to the compiled program. When running the program, the analysis information used by GPROF is generated to show the time consumption of your program.