Reference Blog: http://www.cnblogs.com/qytan36/archive/2010/05/25/1743955.html
GCC compiled c source code has four steps: preprocessing-----> Compiling----> Assembly----> Links
Four-stage function: (the corresponding file suffix is in sequence:. I>.s>.o>.exe)
The code of the introduced header file is added to the current file. Option "-e" preprocessing. Usage: gcc-e hello.c–o hello.i
"To compile GCC first to check the code's normative, whether there are grammatical errors, etc., after the inspection is correct, GCC translated the code into assembly language. Option "-S" preprocessing. Usage: gcc-s hello.i–o Hello.s. (this option is compiled without assembly, generating assembly code.) )
The assembler stage is to turn the ". S" file generated during the compilation phase into binary target code. Option "-C" preprocessing. Usage: gcc-c hello.s–o hello.o.
Link after a successful compilation, the link stage is entered. No option link usage: gcc hello.o–o hello.exe.
Comments:
In the link stage, the compiler is in fact the system standard header files corresponding to the implementation of the corresponding link library, such as stdio.h corresponding to the library file named Libc.so.6, link into their own assembly generated by the. o file. Finally, the executable program is generated.
You can use the LDD command to view the dynamic library load situation.
function library is generally divided into static library and dynamic library two kinds. Static library refers to the compilation of links, the library files of the code are all added to the executable file, so the resulting file is relatively large, but at run time also no longer need the library file. The suffix is generally ". a". Dynamic libraries In contrast, when compiling a link does not add the code of the library file to the executable file, but the library is loaded by the runtime link file when the program executes, which can save the system overhead. The general suffix of the dynamic library is named ". So", as described in the previous libc.so.6 is a dynamic library. GCC uses dynamic libraries by default at compile time.
Linux GUN gcc compilation four processes: preprocessing, compiling, compiling, linking