Install a Compiler & VS Code

C++ · Lesson 2 of 32 8 min read Updated

To write C++ you need two tools: an editor to type your code and a compiler to turn it into a program. In this lesson you will install a modern compiler on your operating system, set up Visual Studio Code (VS Code), and check that your setup understands C++23.

There are three major C++ compilers. All of them are free.

CompilerCommandMade byCommon on
GCCg++GNU projectLinux, Windows (through MSYS2)
Clangclang++LLVM projectmacOS, Linux, Android
MSVCclMicrosoftWindows (Visual Studio)

Which compiler version do you need?

This course uses C++23 features such as std::println. A compiler only supports a feature from a certain version onwards, so check your version before you start. These are the first versions whose standard library supports std::print and std::println:

Compiler and libraryFirst version with std::print
GCC (libstdc++)GCC 14
Clang with libc++Clang 18 (partly in 17)
MSVCVisual Studio 2022 version 17.7 (compiler 19.37)

On Linux, Clang uses GCC's library (libstdc++) by default, so what matters there is the installed GCC version. Newer is always better: GCC 16, for example, was released on 30 April 2026. If your compiler is older and cannot find <print>, you can still follow the course by printing with std::cout, which Your First C++ Program also teaches.

Installing on Windows

You have two good choices on Windows.

Option 1: Visual Studio (MSVC). Download Visual Studio Community (free for students and individuals) from Microsoft. In the installer, tick the workload Desktop development with C++. This gives you the MSVC compiler and a full IDE. Visual Studio is the easiest choice if you want buttons rather than commands.

Option 2: GCC through MSYS2 (works well with VS Code). MSYS2 is a free collection of tools that brings GCC to Windows.

  1. Download and run the installer from the official site msys2.org, keeping the default folder C:\msys64.
  2. Open the MSYS2 UCRT64 terminal from the Start menu.
  3. Install the compiler toolchain with the command below and press Enter to accept the defaults.
  4. Add C:\msys64\ucrt64\bin to your Windows Path environment variable, then open a new terminal.
Terminal
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

Now check the installation in a normal PowerShell window:

PowerShell
g++ --version
Output
g++.exe (Rev2, Built by MSYS2 project) 16.2.0
...

Your version and build text will differ. Any version from 14 upwards is fine for this course.

Installing on Linux and macOS

On Ubuntu or Debian, the build-essential package installs GCC, make and the usual headers. Install Clang too if you want to compare compilers.

Terminal
sudo apt update
sudo apt install build-essential clang
g++ --version
clang++ --version

On macOS, open Terminal and install Apple's command-line tools, which include Apple Clang:

Terminal
xcode-select --install
clang++ --version

Apple Clang follows its own version numbers and can lag behind the open-source LLVM releases. If <print> is missing, install a newer GCC or LLVM with a package manager such as Homebrew, or use std::cout until you update.

Setting up VS Code

VS Code is a free, lightweight editor that works on all three systems.

  1. Install VS Code from code.visualstudio.com.
  2. Open the Extensions panel (Ctrl+Shift+X) and install C/C++ by Microsoft. It adds code completion, error squiggles and debugging.
  3. Create a folder for your practice, for example cpp-practice, and open it with File, Open Folder.
  4. Create a file named hello.cpp.

You can always compile from VS Code's built-in terminal (Ctrl+backtick). To compile with one keyboard shortcut instead, create a file .vscode/tasks.json in your folder:

JSON
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Build C++23",
      "type": "shell",
      "command": "g++",
      "args": ["-std=c++23", "-Wall", "-Wextra", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
      "group": { "kind": "build", "isDefault": true },
      "problemMatcher": ["$gcc"]
    }
  ]
}

Press Ctrl+Shift+B to build the file you have open. The flags mean: -std=c++23 uses the C++23 rules, -Wall -Wextra turn on helpful warnings, and -g adds debugging information. The $gcc problem matcher shows compiler errors in VS Code's Problems panel.

Check that C++23 works

Save this program as hello.cpp, then compile and run it.

C++
#include <print>

int main() {
    std::println("Compiler is ready, Aarav!");
    std::println("C++ standard in use: {}", __cplusplus);
}
Terminal
g++ -std=c++23 -Wall -Wextra hello.cpp -o hello
./hello
Output
Compiler is ready, Aarav!
C++ standard in use: 202302

__cplusplus is a number the compiler defines to show which standard it is using. Recent GCC and Clang versions print 202302, which means C++23 (year 2023, month 02); some older compilers print a slightly different number for their early C++23 mode. On Windows, run .\hello.exe instead of ./hello.

With MSVC, open the Developer Command Prompt for VS and compile with cl /std:c++latest /EHsc /W4 hello.cpp. MSVC reports 199711 for __cplusplus unless you also pass /Zc:__cplusplus, which is a well-known MSVC quirk. Microsoft has announced that MSVC Build Tools 14.52, expected in November 2026, accept a plain /std:c++23 switch.

Common mistakes

  • Forgetting -std=c++23. GCC 16 uses C++20 rules by default (GCC 11 to 15 used C++17), so <print> may not be found. Always pass the standard you want.
  • Adding the wrong folder to Path. On Windows, the folder must contain g++.exe, for example C:\msys64\ucrt64\bin. Open a new terminal after changing Path.
  • Saving the file as hello.cpp.txt. Turn on file extensions in File Explorer so you can see the real name.
  • Running an old program. If your changes do not appear, you probably ran the program without compiling again.

Key points

  • You need an editor and a compiler; GCC, Clang and MSVC are the three major free compilers.
  • std::print needs GCC 14, Clang 18 with libc++, or MSVC 19.37 (Visual Studio 2022 17.7) or newer.
  • On Windows, use Visual Studio, or GCC from MSYS2 with VS Code; on MinGW GCC 14 and 15, link <print> programs with -lstdc++exp.
  • Compile with g++ -std=c++23 -Wall -Wextra file.cpp -o name and run the result.
  • VS Code with Microsoft's C/C++ extension and a tasks.json gives you one-key builds.

Exercise

Install a compiler using the steps for your system. Then write a program that prints your name on the first line and your city on the second line using std::println. Compile it with warnings turned on and run it. Finally, check your compiler version with --version and write it down.

Show solution
C++
#include <print>

int main() {
    std::println("Name: Meera");
    std::println("City: Kochi");
}
Terminal
g++ -std=c++23 -Wall -Wextra about.cpp -o about
./about
Output
Name: Meera
City: Kochi

If the compiler says it cannot find <print>, check that you passed -std=c++23 and that your compiler version is new enough.

Quick Quiz

1. Which flag tells GCC to use C++23 rules?

2. What is the first GCC version whose library supports std::print?

3. On Windows with MinGW GCC 14 or 15, what extra option do std::print programs need when linking?

4. Which VS Code shortcut runs the default build task from tasks.json?

Learn C++ with a mentor

Free lessons get you started. Our Java, C & C++ Programming training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call