Compile & Link

Source: Internet
Author: User

Here is my personal experience on compilation and linking.

Compile -->

Xxx. cpp ---> XXX. O must also provide three tables: unresolved symbol table, exported symbol table, and address redirection table.

Unresolved symbol table: defines the variables or functions required by the CPP file.

Export symbol table: it refers to the variables and functions provided by the CPP file (external link mode ).

Address redirection table: the address is reset after external links are established.

Link -->When the linker links, it first determines the location of each target file in the final executable file. Access the address redirection table of all target files and redirect the recorded addresses (that is, add the starting address of the compilation unit in the executable file ). Traverse the unresolved symbol tables of all target files, and search for matched symbols in all exported symbol tables, enter the actual address on the location recorded in the unresolved symbol table (also add the starting address of the compilation unit with the definition of the symbol in the executable file ). Finally, write the content of all the target files in their respective locations and do some other work. An executable file will be released.


Link Method:

External link: it is the default link between functions and variables. After the functions and variables in the CPP file are compiled, this information must be included in the export symbol table.

Internal link:IfStaticThe keyword is located before the declaration of a global function or variable, indicating that the compilation unit does not export the symbol of this function/variable. Therefore, it cannot be used in other compilation units. (Internal link ). If it is a static local variable, the variable is stored in the same way as the global variable, but the symbol is still not exported.

Note: For external links, you must ensure thatProgramDuplicate symbols cannot appear in other compilation units within the specified range. Internal links cannot be used in other compilation units. [Here, the compiling unit is the CPP file by default]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.