Setting Up a C++ Compiler
Install g++, clang or MSVC, configure your environment, and verify your first compilation.
Setting Up a C++ Compiler is a free C++ Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why You Need a Compiler
C++ is a compiled language. Source code is translated into machine code by a compiler before it runs. Three compilers dominate the ecosystem.
The Big Three: g++ clang MSVC
Pick a compiler based on your platform:
- g++ (GNU) — Linux default, available on macOS and Windows via MinGW
- clang++ (LLVM) — macOS default, fast diagnostics
- MSVC (Microsoft) — Windows native, ships with Visual Studio
Installing g++ on Linux
On Debian or Ubuntu install the build essentials package which pulls in g++ automatically.
sudo apt update
sudo apt install build-essential
g++ --versionInstalling clang on macOS
On macOS, Xcode command line tools include clang. One command sets you up.
xcode-select --install
clang++ --versionInstalling MSVC on Windows
Download the free Visual Studio Community edition and select the "Desktop development with C++" workload. This installs MSVC plus the Windows SDK.
Choosing a Standard Version
Modern C++ has yearly revisions. Most projects use C++17 or C++20. Pass the standard explicitly with a flag.
g++ -std=c++20 main.cpp -o mainOptional: Use a Build System Later
For a single file, calling the compiler directly is fine. Real projects use CMake or Make. We will introduce CMake in a later course.
Editor and IDE Choices
Popular editors that pair well with C++:
- VS Code with the C/C++ extension
- CLion by JetBrains
- Visual Studio on Windows
- Vim or Neovim with clangd
Verifying Your Setup
Open a terminal and run the compiler with the version flag. If you see a version number, you are ready to go.
g++ --version
clang++ --versionSetting Up clangd for Intellisense
Modern editors use clangd for autocompletion and diagnostics. Most distributions install it alongside clang. Restart your editor after installing.
Warnings: Always On
Enable warnings from day one — they catch bugs early. Add -Wall -Wextra to every compilation. Treat warnings as errors with -Werror once you are comfortable.
Quick Check
Which flag tells g++ to compile against the C++20 standard?
Recap
Pick a compiler for your platform, install it, choose a C++ standard with -std=, and turn on warnings. You are now ready to compile your first program.
Frequently asked questions
Is the “Setting Up a C++ Compiler” lesson free?
Yes — the full text of “Setting Up a C++ Compiler” is free to read here on the web, and the C++ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C++ Academy course, upgrade to CoddyKit PRO.
What will I learn in “Setting Up a C++ Compiler”?
Install g++, clang or MSVC, configure your environment, and verify your first compilation. You practise C++ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C++ Academy?
No prior experience is required. C++ Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Setting Up a C++ Compiler” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C++ Academy lesson?
Yes. Every C++ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.