bhylu.com

Advertisements

C++ Compiler Setup

Choose a C++ driver, save a real .cpp file and distinguish compiler errors from linker errors.

How it works

Use a C++20-capable compiler and matching standard library. GCC uses g++, Clang uses clang++, and a portable Zig toolchain provides zig c++. The command shown below uses c++ as the generic driver name. On Windows, extract a stable official Zig archive into your tools folder and invoke its zig.exe by its full path; no global PATH change is required. Save source in a separate exercises folder. The first compile may take longer while a portable toolchain prepares its runtime.

Run it locally

Use a C++20 compiler and matching standard library in a separate lab folder. The command uses c++; substitute g++, clang++ or zig c++ for your toolchain. C++ does not currently run in Bhylu’s browser playground. Apache, PHP and MySQL are not needed.

c++ -std=c++20 -Wall -Wextra -Wpedantic -Werror compiler-workflow.cpp -o lesson

On Windows use -o lesson.exe and run .\lesson.exe in PowerShell. On Unix-like systems run ./lesson. Thread examples may need -pthread on your platform.

Download the complete C++ source. Run file labs in a private empty directory, away from existing reports.

Example

C++20 · compiler-workflow.cpp

#include <iostream>

int main() {
    std::cout << "C++ build ready\n";
}

Expected result

C++ build ready

A build parses and checks the translation unit, creates machine code and links its required library. A diagnostic about a missing declaration is different from a linker message about a missing definition. Enable warnings from the start and fix the first meaningful error. These examples target C++20, not whichever mode happens to be the compiler default.

Your first compiler setup

  1. Download a stable archive for your processor from official Zig downloads, then extract it into your tools folder. GCC and Clang are alternatives if already installed with a suitable C++ standard library.
  2. Create an empty exercises folder. Save this source as compiler-workflow.cpp, checking that Windows has not retained an extra .txt extension.
  3. Open PowerShell in the exercises folder. Replace the example compiler path below with your actual extracted zig.exe path. The call operator & handles a quoted executable path.
  4. After a successful build, run .\lesson.exe and read its output. A failed build must be fixed before running an old executable.
& "C:\Tools\zig\zig.exe" c++ -std=c++20 -Wall -Wextra -Wpedantic -Werror compiler-workflow.cpp -o lesson.exe

GCC uses g++ and Clang uses clang++. No PHP, Apache or MySQL configuration change is needed.

Consult the WG21 C++ working group and the C++ Core Guidelines for language references and design guidance. Check the selected standard version and your implementation’s library support.

Advertisements