Source code compilation and linking process Introduction

Reference article: https: //blog.csdn.net/calm_agan/article/details/86659138 

  • Foreword

After we finished using Visual Studio and other IDE source code (.c or .cpp file), after compiling and linking the two final steps to generate dynamic link library file (DLL) or executable file [.exe (WIndows format) or .out (Linux format)].

  • Compile

VS default compiler tool is cl.exe, as well as commonly used compiler gcc. Compilation is divided into pre-compile, compile, assemble three steps.

Precompiled:

Source code files associated header, the precompiler] [pre-compiled into a format .i file. Pre-compilation process, the main process that begins with the source code of pre-compiled instructions #. After .i file after the pre-compiled and does not contain any macro definitions.

 Such as: (1) expand all macro definitions (#define); (2) pre-processing all the conditional compilation directives (# if, # ifdef, # else, # endif, etc.);

                     (3) The file contains pre-compiled instructions is inserted into the location (#include); (4) removal of all the comment lines (//, / * * /);

                     (5) retain all compiler directives (#program) 

Compile:

After the pre-compiled file, a series of lexical analysis, syntax analysis, semantic analysis and optimization, resulting in the format .s assembly code files.

compilation:

The assembler code into binary machine language, that is, the format .obj (Windows systems) or .o (Linux system) of the target file. In general, each source file should correspond to a target file.

  • link

VS default linker tool is link.exe

Linking process is to deal with mutual references between various modules enable properly link up between the various modules. The program will link a set of object modules formed after compiling and libraries they need link together to form a complete load model.

Links mainly to solve the address and control distribution, symbol resolution and relocation of several steps. When generating object files at compile time, will shelve those external references, and these external references is determined, the linker at link time, will go to the appropriate module name to find the corresponding symbol based on the symbol at link time. After the symbol to be determined before the linker rewrites those addresses undetermined symbol of this process is the relocation. Links are generally divided into static linking, dynamic linking and dynamic linking three operation when loaded.

 

 

Guess you like

Origin blog.csdn.net/jgj123321/article/details/94602620
Recommended