C Programming • Introduction to Computer, Programming & algorithms
C Programming / Linker

Linker

Notes 1 Introduction to Computer, Programming & algorithms

A linker is a system program that combines object files and required library files to create a single executable program.

Notes

What is a Linker?

A linker is a system program that combines object files and required library files to create a single executable program.

💡 In Simple Words

After a program is compiled and assembled, the linker joins the required pieces together and prepares the final executable program.

Why is a Linker Needed?

A large program may be divided into multiple source files and may use functions from libraries. The linker combines these separate parts so that the complete program can be executed.

OBJECT FILES + LIBRARY FILES ↓ LINKER ↓ EXECUTABLE FILE

Functions of a Linker

  • Combines multiple object files.
  • Links required library files.
  • Resolves references to functions and variables defined in other modules or libraries.
  • Assigns or adjusts final memory addresses through relocation.
  • Produces the final executable file.

Input and Output

Item Description
Input Object files and required library files.
Processing Combines modules and resolves external references.
Output A single executable file.

Linking Process

SOURCE CODE ↓ COMPILER ↓ ASSEMBLER ↓ OBJECT FILES ↓ LINKER + LIBRARIES ↓ EXECUTABLE

Types of Linking

1. Static Linking

In static linking, the required library code is included in the executable file during the linking process.

2. Dynamic Linking

In dynamic linking, some library code is linked at runtime using shared library files.

Static Linking Dynamic Linking
Library code is included in the executable. Shared library code is linked when required.
Executable can be larger. Executable can be smaller.
Less dependence on external libraries at runtime. Depends on required shared libraries being available.

Example

Suppose a C program uses a library function such as printf(). After compilation and assembly, the linker connects the required library information with the object code to create the final executable program.

📌 Remember

Linker = Combines object files + libraries → Executable

Quick Revision

Point Remember
Input Object files + libraries
Main Job Combines modules and resolves references
Output Executable file
Types Static linking and Dynamic linking

Important Exam Questions

Short Answer Questions

  1. What is a linker?
  2. Why is a linker needed?
  3. What are the inputs of a linker?
  4. What is the output of a linker?
  5. What is static linking?
  6. What is dynamic linking?

Long Answer Questions

  1. Define a linker and explain its functions.
  2. Explain the linking process from object files to executable file.
  3. Differentiate between static linking and dynamic linking.
🎥 Recommended Learning

Watch an easy explanation of linker and the program translation process.

▶ Watch: Linker in Compiler — Hindi Explanation

📝 Handwritten Notes

A short handwritten-style revision sheet for Linker will be provided here.

🧠 Mind Map

Use the mind map for quick revision of linker, object files, libraries and executable generation.