C++ Programming/Compiler/Linker

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Contents

[edit] Linker

The linker is a program that is responsible for linking and resolving linkage issues, such as the use of symbols or identifiers which are defined in one translation unit and are needed from other translation units, this information is created by the compiler. Symbols or identifiers which are needed outside a single translation unit must have external linkage, in short, the linker's job is to resolve references to undefined symbols by finding out which other object defines a symbol in question, and replacing placeholders with the symbol's address. Of course, the process is more complicated than this; but the basic ideas apply.

Linkers can take objects from a collection called a library. Depending on the library (system or language or external libraries) and options passed, they may only include its symbols that are referenced from other object files or libraries. Libraries for diverse purposes exist, and one or more system libraries are usually linked in by default. We will take a closer look into libraries on the Libraries Section of this book.

[edit] Linking

The process of connecting or combining object files produced by a compiler with the libraries necessary to make a working executable program (or a library) is called linking. Linkage refers to the way in which a program is built out of a number of translation units.

C++ programs can be compiled and linked with programs written in other languages, such as C, Fortran, and Pascal. When programs have two or more source programs written in different languages, you should do the following:

  • Compile each program module separately with the appropriate compiler.
  • Link them together in a separate step.
[edit] Static Linkage
TODO

TODO
Complete, use global const case as example

[edit] Internal Linkage
TODO

TODO
Complete

[edit] External Linkage
TODO

TODO
Complete