Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

How C++ Works · Lesson 8 of 25

Linker

A free lesson from Swipe Coding · C++, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
One last step stitches everything into a single runnable program. 🧵

After the compiler produces one or more object files, a tool called the "linker" combines them into a single, complete, runnable program called an "executable". The linker's job is to resolve every reference to a function or variable that lives somewhere else, and stitch all the pieces together.

For example, when your code calls a function like the one behind std::cout to print text, that function's actual machine code lives inside the C++ "standard library", not in your own object file. The linker finds that code and links it into your final program, so the reference actually points somewhere real.

g++ main.o -o main
// produces the executable: main (or main.exe on Windows)
The linker takes the object file main.o, links in the pieces it needs from the standard library, and produces the executable "main".
Quick check

What is the linker's main job?

Fill in the blank

The linker combines object files and libraries into a single runnable ____.

🤖
Forget a piece and the linker will tell you exactly what is missing. ⚠️

If the linker cannot find the code for something your program refers to — for example, you call a function that was never actually defined anywhere — it reports a "linker error", separate from a compiler error. This can happen even when your code has perfectly valid syntax.

True or false

Linking happens before compiling in the C++ build process.

🤖
That's the full journey, start to finish. 🏁

In summary, a C++ program goes through four stages before it can run: the preprocessor expands directives, the compiler translates the result into object code, the linker combines object files and libraries into an executable, and finally the operating system runs that executable directly — no virtual machine involved at any point.

Chapter quiz

How C++ Works

10 questions · pass with 60% — just like in the app.

Quick check

What is C++ source code?

Fill in the blank

C++ source code files conventionally use the extension ____.

True or false

The preprocessor runs before the compiler translates the code.

Quick check

What does the "#include" directive do?

Fill in the blank

Preprocessor directives always begin with the character ____.

Quick check

What does the C++ compiler produce from your source code?

True or false

An object file produced by the compiler is always immediately runnable on its own.

Fill in the blank

The ____ combines object files and libraries into a single runnable executable.

Quick check

What is the correct order of the C++ build process?

True or false

C++ programs run inside a virtual machine, similar to some other languages.

Keep your streak going in Swipe Coding

Swipe through every level of C++ on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →