TEST.c
#include <stdio.h>
int main () {
printf ("hello\n");
return 0;
}
1. Preprocessing phase
Because the header file is used in test.c, gcc first loads the contents of the head file stdio.h into the test.c header at compile time.
GCC-E Test.c-o test.i
E indicates that only preprocessing is performed. o indicates the output file name.
2. Compile Stage
Lexical analysis: keywords, identifiers and so on are correct;
Syntax Analysis: The syntax of the statement in the program is correct;
Semantic Analysis: The logical meaning of the statement is correct.
Gcc-s Test.i-o Test.s
s indicates that only compile, generate a compilation file.
3. Assembly phase
Translates the assembler into a binary file that the CPU can recognize, which is the target file.
Gcc-c Test.c-o TEST.O
c indicates that only the assembly is carried out.
4. Link Stage
Link all the target files in the program with the required library files
Gcc-test.o-o Test
Add:
function Library Implementation:
Information about the print function, the opening or closing function of the file, the application of the memory space with the release function, the mathematical calculation function.
PS: In object-oriented languages, functions are encapsulated in classes, so libraries become class libraries.
The use of function library is divided into static link and dynamic link two kinds.
1) static linking means that the compilation system links the program's target files with the required library files at the link stage so that the resulting executable can run without a library of functions. It's like a rocket that's packed with fuel and oxygen to fly in the air.
2) dynamic linking means that the compilation system does not link the target file and the function library file in the link stage, but waits until the program needs to use it to link the function library when it is running.
A static link produces an executable file that is larger in size but more efficient to run. The use of dynamic link files is small, running less efficient.
In a specific application, if you have multiple source files that need to call the library, you should choose how to link dynamically. When only a few source files need to call the library, you should choose how to statically link. A library of functions that can be statically linked is called a static library, and can be dynamically linked to a library or shared library.
GLIBC(GNU Library C) is the GNU-launched C- language function library, which complies with the ISO C and POSIX standards.
InLinuxSystem,GlibcDistributed in/Lib and /usr/lib directory, where /lib The library file in the directory is mainly for /bin Directory of system programs used, /usr/lib The library file in the directory is mainly for /< Span style= "font-family: Microsoft Jas Black;" lang= "en-US" >usr directory user program used.
The following is a partial PNG function library file under the/usr/lib directory:
Libpng. A
Libpng. La
Libpng. so
Libpng. So.3
Libpng. so.3.16.0
The suffix is a static library file, the suffix of la is used to record the library file information of the dynamic library file, the suffix so is the dynamic library file
C Language Review (1)