Installing C++ Compiler
To write and run programs in C++, you need a compiler. A compiler converts C++ source code into machine code so the computer can execute the program.
Some popular C++ compilers include GCC, Clang, and MSVC. The installation process depends on the operating system you are using.
Install C++ Compiler on Windows
Follow these steps to install a C++ compiler on Windows:
- Download and install MinGW or MSYS2.
- During installation, select the g++ compiler.
- Add the bin folder to the system PATH.
- Open Command Prompt.
- Type the following command to verify installation:
g++ --version
If the compiler is installed correctly, the version information will be displayed.
Install C++ Compiler on Linux
Most Linux distributions already include the GNU compiler. If it is not installed, you can install it using the package manager.
For Ubuntu or Debian systems:
sudo apt update sudo apt install g++
Check the installation:
g++ --version
Install C++ Compiler on macOS
On macOS, the easiest way to install a C++ compiler is through Xcode Command Line Tools.
Open the terminal and run:
xcode-select --install
This will install the required compilers including clang++.
Test the Installation
Create a simple C++ program to test the compiler.
#include <iostream>
using namespace std;
int main() {
cout << "C++ compiler is working!";
return 0;
}
Compile the program using the following command:
g++ program.cpp -o program
Run the program:
./program
Next Topic
Next, learn about C++ IDE Setup.