
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How does the compilation/linking process work in C/C++?
The compilation of a C++ program consists of three steps −
- Preprocessing − In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. It handles preprocessing directives like #include, #define, etc.
- Compilation − The compilation takes place on the preprocessed files. The compiler parses the pure C++ source code and converts it into assembly code. This in turn calls the assembler that converts the assembly code to machine code(binary) as Object files. These Object files can refer to symbols that are not defined. The compiler won't give an error unless the source code is not well-formed. Syntax errors, failed overload resolution errors, etc occur in this step. Also note these object files can be used as static libraries as well.
- Linking − The linker is produces the final compilation output from the object files the compiler produced. This output can be a shared (or dynamic) library or an executable. It links the object files by replacing the undefined references with the correct addresses. These symbols should be defined in other object files or in the libraries. If they are defined in libraries other than the standard library, you need to explicitly pass them to the compiler as an argument so that they can be found and linked.
- Related Articles
- What is the process of compilation and linking in python?
- MCQ on Memory allocation and compilation process in C
- How does #include work in C++?
- How does the Comma Operator work in C++
- How does a vector work in C/C++
- How does a vector work in C++?
- How does Garbage Collector work in C#
- Knowledge Process Outsourcing (KPO) - What is it and How Does It Work?
- How does generic lambda work in C++14?
- How does the magnets work?
- How does the array_diff_key() work in PHP?
- How does the Microstrip antenna work?
- How does the Selenium WebDriver work?
- How does the discordancy testing work?
- How does the WannaCry malware work?

Advertisements