Getting Started

Getting Started

Install a compiler, write your first program, and build from the command line.

Getting Started

1. Choose a compiler

Use one of these toolchains:

2. Create a first file

#include <iostream>

int main() {
    std::cout << "Hello, C++!\n";
}

Save it as main.cpp.

3. Compile it

GCC / Clang

g++ -std=c++23 -Wall -Wextra -pedantic main.cpp -o app

MSVC Developer Command Prompt

cl /std:c++23 /W4 main.cpp

4. Run it

./app

5. Mental model

A C++ source file is compiled into machine code. The compiler checks syntax and types before you run the program.

6. Next steps

7. A better first compile command

As soon as you move past "hello world", prefer separate debug and release builds.

g++ -std=c++23 -Wall -Wextra -Wpedantic -g -O0 main.cpp -o app-debug
g++ -std=c++23 -Wall -Wextra -Wpedantic -O2 main.cpp -o app-release

The debug build helps investigation. The release build shows the performance and code generation you will eventually ship.

8. First project structure

project/
    src/
        main.cpp
    include/
    build/

Start small, but keep generated files out of your source directories.

9. Habits worth adopting immediately