Appendix A

Setting Up a Local C++ Toolchain

Optional — OnlineGDB is the default

Appendix A — Setting Up Your C++ Toolchain (Optional)

This appendix is optional for Coding 1 and Coding 2. The default workflow for this course is OnlineGDB — see Appendix D. OnlineGDB runs the same g++ toolchain in your browser, so you can ship every project without installing anything. Coding 3 will introduce a local toolchain properly. If you want to set up local C++ now anyway — for offline work, faster iteration, or just curiosity — this appendix walks you through it.

This is a get it working in 30 minutes guide. We’re not going to teach you everything about the tools — we’re going to get you to a working hello.cpp that compiles and runs. That’s it. Anything more is for later.

You need three things on your machine:

  1. A C++ compiler — turns your code into a runnable program.
  2. A text editor — for writing the code.
  3. A terminal — for running the compiler and the resulting program.

Pick your operating system below and follow the steps. Don’t skip the verification step at the end.


Option A: macOS

Step 1 — Install the Apple Command Line Tools

Open the Terminal app (Spotlight: hit Cmd+Space, type terminal, press Enter).

In the terminal, type:

xcode-select --install

A dialog will appear. Click Install. It’ll take 5–15 minutes depending on your internet speed. This installs clang/g++ and the standard C++ headers.

When it’s done, verify by typing:

g++ --version

You should see version output starting with Apple clang version .... If you do, the compiler is installed.

Step 2 — Install Visual Studio Code

Download from code.visualstudio.com and install like any other Mac app (drag to Applications). Open it once to confirm it runs. That’s it — no extensions required for this course.

Step 3 — Verify

Skip to “Verification” at the bottom of this page.


Option B: Windows

You have two reasonable paths here. We recommend Option B1 (WSL) because it gives you a Linux-style environment that matches what most professional C++ devs use. Option B2 (MSYS2) is a fine native Windows alternative.

WSL is “Windows Subsystem for Linux.” It runs a real Linux environment inside Windows. The C++ tools we use work natively there.

  1. Open PowerShell as Administrator (right-click PowerShell, “Run as administrator”).

  2. Run:

    wsl --install -d Ubuntu
  3. Restart your computer when prompted.

  4. After restart, an Ubuntu terminal will open automatically and ask you to create a username and password. Pick something simple. Remember it.

  5. Once you’re in the Ubuntu shell, run:

    sudo apt update
    sudo apt install -y g++ build-essential
  6. Verify:

    g++ --version

    You should see GCC version output. Compiler installed.

Option B2 — Native Windows with MSYS2

  1. Download MSYS2 from msys2.org and install.

  2. After installation, open the “MSYS2 MINGW64” terminal from the Start menu.

  3. Run:

    pacman -Syu

    Close the terminal when prompted, reopen MSYS2 MINGW64, then run:

    pacman -S --needed mingw-w64-x86_64-gcc
  4. Add C:\msys64\mingw64\bin to your Windows PATH (System → Environment Variables → Path → New). This lets you use g++ from any Windows terminal.

  5. Open a new PowerShell or Command Prompt window and verify:

    g++ --version

Install Visual Studio Code

Download from code.visualstudio.com and install. If you used WSL, install the “WSL” extension after first launch (it was previously called “Remote - WSL” — Microsoft renamed it) — it lets VS Code edit files inside your Ubuntu environment seamlessly.


Option C: Linux

Open your terminal.

Step 1 — Install GCC

Ubuntu / Debian:

sudo apt update
sudo apt install -y g++ build-essential

Fedora:

sudo dnf install -y gcc-c++ make

Arch:

sudo pacman -S base-devel

Step 2 — Verify the compiler

g++ --version

Should print a GCC version string.

Step 3 — Install Visual Studio Code

Most distros have an official package or a snap. Download from code.visualstudio.com and install with your package manager.


Verification

Regardless of your OS, everyone does this last step. It’s how you know the toolchain works together.

1. Make a folder for your code

Pick a sensible location. Examples:

  • macOS / Linux: ~/code/coding1/
  • Windows (WSL): ~/code/coding1/
  • Windows (native): C:\code\coding1\

In your terminal:

mkdir -p ~/code/coding1
cd ~/code/coding1

(On Windows native, use mkdir C:\code\coding1 and cd C:\code\coding1.)

2. Write hello.cpp

Open VS Code. File → Open Folder → select the folder you just made. Create a new file named hello.cpp. Paste the following:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, world." << endl;
    return 0;
}

Save the file.

3. Compile

In your terminal (still inside the folder containing hello.cpp):

g++ -std=c++17 -Wall -Wextra hello.cpp -o hello
  • -std=c++17 tells the compiler to use the C++17 standard. Some textbook examples use modern features (brace-init for structs, auto, etc.) that older defaults won’t accept. Type it every time.
  • -Wall -Wextra turns on extra compiler warnings. Get used to typing them — they save you bugs.
  • -o hello names the output program hello (or hello.exe on native Windows).

If the command finishes with no output, the compile succeeded. No output is good output.

If you see warnings or errors, read them. Most beginner errors are typos in hello.cpp. Compare your file letter-by-letter to the version above.

4. Run

./hello

(On native Windows, just type hello or hello.exe — no ./.)

You should see:

Hello, world.

If you do: you’re done. The toolchain works. Close this page and head back to Chapter 1, section 1.6.


When Things Go Wrong

If g++ --version failed: the compiler isn’t installed or isn’t on your PATH. Re-do the installation steps for your OS. On Windows native, double-check the PATH modification — many failures come from skipping that step.

If g++ hello.cpp ... failed: read the error message. The most common cause is a typo in the file. The second most common cause is running the command in a folder that doesn’t contain hello.cpp. Run ls (Mac/Linux) or dir (Windows) to confirm.

If ./hello printed command not found: the compile probably didn’t actually create the program. Try ls -la to see what’s in the folder. If you don’t see a file named hello (or hello.exe), the compile step silently failed. Run it again and look for any warnings.

If ./hello printed something other than Hello, world.: you compiled a different file than you saved. Double-check by opening hello.cpp in your editor and confirming it matches the version above. Save again. Recompile.

If you’re stuck for more than 20 minutes: ask a peer, your instructor, or your AI for help. The toolchain is a setup task, not a learning task — there’s no merit badge for figuring it out alone.


Optional: A Slightly Nicer Editor Experience

Once everything above works, you can optionally install these VS Code extensions for a nicer C++ editing experience:

  • C/C++ by Microsoft — adds syntax highlighting, autocomplete, and click-to-definition.
  • Code Runner — adds a “play” button that compiles and runs the current file with one click.

These are conveniences, not requirements. The course assumes you can compile and run from the terminal. If your VS Code setup mysteriously breaks one day, fall back to the terminal and you’ll always be fine.


Up next: Back to Chapter 1, Section 1.6.