Skip to content
BENIBIX Learn

Linker

Development⚙️ Compilers & RuntimesCompilation

Also known as Linking, Link Step

A tool that joins built pieces of code into one program.

Think of it like

Think of it like stapling loose pages into one book. Each page was written on its own first.

Example

Jack's app has main.c and math.c. Each compiles to its own .o file. The linker joins them, and the program prints 5.

Why it matters

Big programs are built from thousands of files. Linking is what lets each one be compiled on its own.

Definition

A linker is a tool that joins built pieces of code into one program you can run. A compiler often turns each source file into its own object file. These files call each other but do not yet know where the other parts are. The linker finds every call and connects it to the code it needs, including libraries. The result is one finished program file.

Example code

console
$ gcc -c math.c
$ gcc -c main.c
$ gcc main.o math.o -o app
$ ./app
5
Two files compile on their own, then one link step joins them into app.

Common mistake

Reading an undefined reference error as a typo in your code. It means the linker could not find a file you forgot to add.

Key takeaways

  1. 1
    Pieces in. Object files and libraries.
  2. 2
    Calls connected. Each to its code.
  3. 3
    One program out. Ready to run.