Code Editor • Compiler • Windows Setup • Mac Setup • Linux Setup • Testing Installation
To write and run C++ programs, you need two things:
- A code editor (where you write the program)
- A compiler (which converts your program into machine code)
A compiler is necessary because computers understand machine language, not English-like C++ code.
In this chapter, you will learn how to install a C++ compiler on Windows, Mac, and Linux.
3.1 What Is a C++ Compiler?
A compiler is a software tool that:
- Reads your C++ code
- Checks for errors
- Converts it into machine code
- Creates an executable file that your computer can run
Examples of popular C++ compilers:
- MinGW (Windows)
- GCC (Linux, Mac, Windows)
- Clang (Mac, Linux)
- MSVC (Microsoft Visual C++)
3.2 What Is a Code Editor?
A code editor is where you write your C++ program.
Recommended editors:
- VS Code (Visual Studio Code) (most popular)
- Dev-C++ (beginner-friendly)
- Code::Blocks
- Visual Studio (IDE)
We will install:
- 👉 Option A — Dev-C++ (easiest for beginners)
- 👉 Option B — VS Code + Compiler (best for future use)
Choose whichever you prefer.
3.3 Option A — Installing Dev-C++ (Beginner Friendly)
✔ Step 1: Download Dev-C++
- Open your browser
- Visit: https://sourceforge.net/projects/orwelldevcpp/
- Click Download
✔ Step 2: Install Dev-C++
- Run the installer
- Click Next
- Select English
- Keep all default settings
- Click Install
✔ Step 3: Run Dev-C++
You will now see a window like:
File | Edit | Search | Execute | HelpDev-C++ comes with a built-in compiler, so you are ready to write and run C++ programs.
3.4 Option B — Installing VS Code + MinGW Compiler (Recommended)
VS Code is modern, powerful, and used by professionals.
Step 1: Download VS Code
- Go to: https://code.visualstudio.com/
- Click Download for Windows
- Install it normally by pressing Next → Next → Finish
Step 2: Install MinGW Compiler (Windows)
- Visit: https://www.mingw-w64.org/
- Download mingw-w64 (64-bit)
- Install with these settings:
- Version: 8.1.0
- Architecture: x86_64
- Threads: posix
- Exception: seh
- Install into:
C:\mingw-w64\
Step 3: Add Compiler to PATH
- Open Control Panel
- Search Environment Variables
- Click Path → Edit
- Add this path:
C:\mingw-w64\bin - Save
Step 4: Check Installation
Open Command Prompt and type:
g++ --versionIf it shows a version number, the compiler is installed successfully.
3.5 Installing C++ Compiler on Mac
Mac uses a built-in compiler called Clang.
✔ Step 1: Install Xcode Command Line Tools
Open Terminal and type:
xcode-select --installPress Install.
Done!
Now your Mac can compile C++ programs.
3.6 Installing C++ Compiler on Linux
Linux usually comes with GCC, but if not:
Open Terminal:
sudo apt update
sudo apt install g++Now GCC is installed.
3.7 Confirming Your Compiler Works
To check if your compiler is installed:
g++ --versionIf you see something like:
g++ (MinGW) 8.1.0Then everything is working!
3.8 Simple Test Program
Write this in your editor:
#include <iostream>
using namespace std;
int main() {
cout << "Compiler Installed Successfully!";
return 0;
}Save it as test.cpp
To run:
g++ test.cpp -o test
testYou should see:
Compiler Installed Successfully!Summary of Chapter 3
- You need both an editor and a compiler
- Recommended tools: Dev-C++ or VS Code + MinGW
- Mac uses Clang, Linux uses GCC
- Always test with
g++ --version - Run your first program to confirm installation
Practice Exercises
Q1. What is a compiler?
Q2. Name two code editors.
Q3. Which command is used to check compiler installation?
Q4. Write the command to install g++ on Linux.
Q5. What does VS Code need separately to run C++ programs?
⭐ Answer Key
A1.
A compiler converts C++ code into machine code.
A2.
VS Code, Dev-C++, Code::Blocks.
A3.
g++ --versionA4.
sudo apt install g++A5.
VS Code needs an external compiler (e.g., MinGW or GCC).