Ch1: Compile
The Compile chapter begins with the most minimal C++ program:
int main() {}
There is no printing, no input, just the bare minimum entry point. From here, we explore how to turn this source code into a binary executable.
Tools We Will Use
To keep things modern and lightweight, we will use:
- PWA Store — to install Progressive Web Apps.
- VS Code (Insiders PWA) or VS Code (PWA) — to write and edit our C++ code directly in the browser.
- gcc — GNU Compiler Collection for building C++ programs.
- clang/LLVM — modern compiler infrastructure for C++.
- Windows MSVC Sysroot (required if using Clang to compile Windows programs)
We will not use Microsoft Visual C++ in this tutorial.
Compiling Across Platforms
Using pure terminal commands, we will learn how to produce different kinds of binaries:
- Windows:
.exefiles - Linux / FreeBSD:
ELFbinaries - macOS:
Mach-Obinaries
This chapter emphasizes understanding compilation without relying on IDEs or build systems. Just the command line, the compiler, and the simplest C++ program.
Workflow
The workflow is straightforward:
- Install the PWA Store and PWA version of VS Code.
- Install a compiler (Clang or GCC). If you are compiling Windows programs with Clang, also install the Windows MSVC Sysroot.
- Write
int main() {}in a new filemain.cpp. - Open a terminal and run
gcc main.cpp -o mainorclang main.cpp -o main. - Observe the generated binary (
main.exe,a.out, ormaindepending on platform).
This exercise shows how C++ source code becomes a runnable program, even with no output.