Setting Up Your C++ Environment
Before you can write C++, you need a compiler that turns your source code into a runnable program, and an editor or IDE to write it in. This lesson walks through the most common setup options.
Choosing a Compiler
The three major C++ compilers are GCC (g++, free and cross-platform), Clang (fast, used by Apple and many Linux tools), and MSVC (Microsoft's compiler, bundled with Visual Studio on Windows). Any of these is fine for learning — what matters is that one is installed and on your system PATH so you can call it from a terminal.
- Windows — install MinGW-w64 (provides g++) or Visual Studio Community.
- macOS — install Xcode Command Line Tools, which includes Clang.
- Linux — install the
build-essentialpackage (Debian/Ubuntu) orgcc-c++(Fedora).
Compiling From the Terminal
Once a compiler is installed, you can compile a single file into an executable with one command. The compiler checks your syntax, translates it to machine code, and links in the standard library.
g++ -std=c++17 -Wall main.cpp -o main
./main
Using an IDE
An IDE (Integrated Development Environment) bundles an editor, compiler integration, and a debugger. Visual Studio Code with the C/C++ extension, CLion, and Visual Studio are all popular choices. An IDE is not required, but it makes catching mistakes and stepping through code much easier as programs grow.
Common Mistakes
- Forgetting the
-std=c++17(or newer) flag, which can cause modern syntax to be rejected by an older default standard. - Not adding the compiler to your system PATH, so the terminal cannot find the
g++command. - Running the source file directly instead of the compiled executable — C++ must be compiled first.
- Ignoring compiler warnings (
-Wall) that often point to real bugs before they cause problems.
Professional Tip
Always enable warnings with -Wall -Wextra while learning. The compiler will flag unused variables, comparison mistakes, and other issues that are easy to miss by eye.
Your Turn
Install a compiler for your operating system, confirm it works by running g++ --version (or your compiler's equivalent) in a terminal, then compile and run the Hello World program from the previous lesson.
Mini Quiz
What must happen to a .cpp file before it can be executed?