Before you write a single interesting line of C++, you need to understand what happens when you press "run." Most beginners treat the build as magic. At a trading firm, the build is the job half the time. So we start here.
What C++ actually is
C++ is a compiled language. Unlike Python or JavaScript, your source code is never run directly. Instead a program called the compiler translates your human-readable .cpp files into machine code the CPU executes directly. This is why C++ is fast: there is no interpreter sitting between your code and the processor at runtime.
The translation happens in stages, and knowing them will save you hours of confusion later:
- Preprocessing — handles lines starting with
#.#includeliterally pastes the contents of another file into yours. - Compilation — turns each
.cppfile into an object file (.o) full of machine code. Each file is compiled independently. - Linking — stitches all the object files (and libraries) together into one executable. If you call a function that exists but never got linked, this is the stage that fails.
"Compiler error" and "linker error" are different animals. A compiler error means your code is malformed in one file. A linker error (often "undefined reference to...") means the code is fine but the definition of something couldn't be found at link time. Beginners waste hours because they don't know which stage failed.
Installing the toolchain
You need two things: a compiler (g++ or clang++) and cmake.
macOS
# installs clang++, the Apple compiler
xcode-select --install
# install cmake via Homebrew
brew install cmakeLinux (Debian / Ubuntu)
sudo apt update
sudo apt install build-essential cmakeWindows
Easiest path is WSL2 (Windows Subsystem for Linux), then follow the Linux steps inside it. This is also closest to the Linux environment trading firms actually deploy on, so it's worth doing. Alternatively, install MSYS2 or use Visual Studio's C++ workload.
Verify everything works:
g++ --version # or: clang++ --version
cmake --versionYour first program
Create a file called hello.cpp:
#include <iostream>
int main() {
std::cout << "Hello, Latency Lab\n";
return 0;
}Line by line, because every piece matters:
#include <iostream>pulls in the input/output stream library so you can print to the console.int main()is the entry point. Every C++ program starts executing here. It returns anintto the operating system.std::coutis the standard output stream. The<<operator sends data to it."\n"is a newline.std::is the namespace the standard library lives in — more on that soon.return 0;tells the OS the program succeeded. Non-zero means failure. This convention matters when your program is one stage in a pipeline.
Compile and run it directly
g++ -std=c++17 -Wall -Wextra hello.cpp -o hello
./helloWhat those flags mean:
-std=c++17— use the C++17 standard. Always specify this. Defaults vary by compiler.-Wall -Wextra— turn on warnings. Always compile with warnings on. They catch real bugs before they run. At a trading firm, warnings are often treated as errors.-o hello— name the output executablehello. Without it you geta.out.
Add -Wall -Wextra -Wpedantic to every compile from day one. The single fastest way to become a better C++ programmer is to read and fix every warning instead of ignoring it.
Building with CMake
Compiling one file by hand is fine. Real projects have dozens. CMake is the build system that manages this — it's what nearly every C++ shop uses, including the order book you'll build in Module 12.
Create CMakeLists.txt next to hello.cpp:
cmake_minimum_required(VERSION 3.16)
project(hello LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(hello hello.cpp)Every line explained:
cmake_minimum_required— the oldest CMake version that can build this. Prevents cryptic failures.project(...)— names the project and declares it uses C++ (CXX).CMAKE_CXX_STANDARD 17— enforce C++17 without you passing-stdby hand.add_executable— build an executable namedhellofromhello.cpp.
Build it the standard "out-of-source" way (keeps generated files out of your source folder):
cmake -S . -B build # configure: read CMakeLists, generate build files into build/
cmake --build build # actually compile
./build/hello # runExercise 00.1 — Make it yours
Get the toolchain working and prove it to yourself:
- Install the compiler and CMake. Run the two
--versioncommands successfully. - Compile
hello.cppboth ways: directly withg++, and via CMake. - Modify the program to also print your name and today's date on separate lines.
- Deliberately break it: delete a semicolon and recompile. Read the error. Then delete the
#includeand recompile. Notice how the errors differ. This is how you learn to read compiler output.
Takeaways
- C++ is compiled: source → object files → linked executable. Three stages, three kinds of failure.
- Compiler errors are per-file and syntactic. Linker errors ("undefined reference") mean a definition was missing at link time.
- Always compile with
-std=c++17 -Wall -Wextra. Warnings are free bug reports. int main()is the entry point and returns 0 on success.- CMake manages real builds.
cmake -S . -B buildthencmake --build build.
Checkpoint · Toolchain
5 questions · pass at 70%
#include <iostream> do during preprocessing?-std=c++17 explicitly?main returning a non-zero value signal to the operating system?-Wall -Wextra?Finished Module 00?
Passing the quiz marks it complete automatically. Or mark it yourself.