Linker (original) (raw)

Last Updated : 11 Apr, 2026

A linker is an essential tool in the process of compiling a program. It helps combine various object modules (output from the assembler) into a single executable file that can be run on a system.

Source code -> compiler -> Assembler -> Object code -> Linker -> Executable file -> Loader

linker

Linking Process: Combining Object Files into an Executable

Types of Linking

Linking is the process of connecting different parts of a program. There are two main types of linking:

**1. Static Linking

A static linker performs two major tasks to prepare a program for execution:

**Symbol Resolution

**Relocation

**2. Dynamic Linking

Dynamic linking happens at runtime, meaning it is performed while the program is running rather than during the compilation process.

**Library Linking: Instead of including all the necessary libraries directly into the executable, the dynamic linker adds the names of shared libraries in the executable image. The actual linking happens when the program is executed.

**Advantages

**Disadvantages

In dynamic linking, libraries are stored in virtual memory, which helps save physical RAM by sharing them across programs.

**Example: If you open a program that uses a system library (like a graphics library), the program will link to that library when it runs.

Please see Static and Dynamic Libraries for a code example in C.

**Features

Applications

  1. **Combining object files: The primary function of a linker is to combine multiple object files into a single executable. This allows for the efficient management and distribution of large software projects, as multiple object files can be combined into a single executable that can be run on a target platform.
  2. **Resolving symbol references: Linkers also resolve symbol references between object files. A symbol is a variable or function that is defined in one object file and used in another. The linker ensures that all symbol references are properly resolved, so that the final executable can run correctly.
  3. **Dynamic linking: Linkers also support dynamic linking, which allows a program to call functions or access variables that are defined in a separate shared library. This allows for more efficient memory usage, as multiple programs can share the same library.
  4. **Library management: Linkers also play an important role in library management. A library is a collection of object files that can be linked into a program to provide additional functionality. Linkers allow developers to easily link libraries into their programs, making it easier to add new functionality to a project.
  5. **Modularity: Linkers also allow for greater code modularity and reusability. By breaking a software program into multiple object files that can be linked together, developers can create more modular and reusable code.

Advantages

  1. **Code Reuse: A linker allows code to be reused across multiple programs by linking in shared libraries, reducing the amount of code that needs to be written and maintained.
  2. **Smaller Executable Files: Dynamic linkers reduce the size of the executable file by linking libraries at runtime, rather than including them in the executable.
  3. **Reduced Memory Footprint: Dynamic linkers allow multiple programs to share the same library in memory, reducing the overall memory usage of the system.
  4. **Reduced Disk Space: With dynamic linking, the libraries only need to be stored on disk once, instead of being copied into the executable of each program that uses them.
  5. **Portability: Linkers allow multiple object files generated by different compilers or written in different languages to be combined into a single executable file, allowing for more flexibility and portability in program.

Disadvantages

  1. **Complexity: Linkers can be quite complex, especially when dealing with large and complex projects. This can make it difficult for developers to understand and troubleshoot issues that may arise.
  2. **Symbol resolution: Linkers must resolve symbols, which are names used in the source code that refer to memory locations. This can be a difficult and time-consuming process, especially when dealing with multiple object files and libraries.
  3. **Compatibility issues: Linkers must be able to work with a variety of object file formats and libraries, which can be challenging. Incompatible object files or libraries can cause errors or crashes during the linking process.
  4. **Performance: Linkers can be resource-intensive and may take a long time to process large projects. This can be a problem for developers working on large-scale projects or for embedded systems with limited resources.
  5. **Security: Linkers can also be a potential security risk if not properly implemented. Insecure linking can lead to vulnerabilities that can be exploited by malicious actors.