GCSE · Computer Science · Eduqas · Spec C500QS

Linking errors

You press Run on code that looks perfect, and the build refuses to make a program. The fix turns out to be nowhere in your own lines.

Computer Science · Linking errors

The code is fine. The build still refuses.

main.c is meant to print the area of a circle of radius 3. The last line is the command that builds it. Press Run, read what the build says, then pick a fix for that last line.

Run means: build the program and, only if the build works, run it. circle_area was written separately and is stored in the file shapes.c.

C, built with GCC
  1. /* main.c */
  2. #include <stdio.h>
  3. #include "shapes.h"
  4. int main(void) {
  5. double r = 3.0;
  6. printf("Area: %.2f\n", circle_area(r));
  7. return 0;
  8. }
  9. $ gcc main.c -o app

The messages are what GCC 13.3 with the GNU linker printed for this exact code (the temporary file name changes every build). Other languages and systems word them differently.

Predict, then check

Look back at the build you just ran. main.c calls circle_area, but main.c never contains the code that works it out.

Where is the code for a routine like circle_area actually kept?

Computer Science · Producing a program

Which stage comes when?

the order in which a program is produced, from first to last

1 · Happens first4 · Happens last
  1. The linker joins the translated program to the library routines it uses

  2. A single executable program is produced

  3. The programmer writes the source code

  4. The source code is translated

Exam line: Source code is written, then translated, then linked to library routines, and only then is a single executable program produced.

Computer Science · Spot the linking error

Will the linker find it?

For each build, decide whether the linker will be able to join the pieces. Think about what the linker can and cannot find.

Still to sort

Linking error (0)

The linker cannot find a routine the program calls.

Where the line is: Translation can have finished perfectly. What matters is whether the linker can find the code.

Links successfully (0)

The linker finds every routine the program calls.

Where the line is: Both things must be true: the library is included and the routine called by that name exists in it.

4 of 4 still to sort.

Exam line: Ask two questions about every routine: is its library included, and does the routine called by that name exist in it?

Computer Science · What went wrong?

Which idea is closest to yours?

A build stops with a message saying the linker cannot find a routine called circle_area. No program appears.

Which idea is closest to what you think is going on?
How sure are you?

Exam line: Linking error: reported during the build, after translation. No executable program is produced until it is corrected.

Computer Science · Your turn

Describe it in your own words

A student's program calls a routine that should come from a library. The program will not build and no executable program appears. Describe the error and explain how it would be corrected. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Why a program that looks perfect can still refuse to build

What you need to know

  • Programs often use code that was written separately from the main program.
  • A library stores pre-written subroutines so that many programs can reuse them.
  • Have a goSam says: 'A library is a building full of books about programming.' In one line, what is a library really?

    A store of pre-written subroutines that many programs can reuse.

    It holds code your program can call, not books to read, and the point is that nobody has to rewrite the same routine every time.

  • Linking is the step that joins your translated program to that separate code, to make a single program that can be executed.
  • The program that does the joining is called a linker.
  • Have a goFinish the sentence: the linker joins the translated program to ______, to make one program that can be executed.

    the separately written code it uses (such as library routines)

    Translating your own code is not enough when part of the program lives somewhere else. Linking is the step that joins the two.

  • A linking error means the program cannot be joined to separately written code that it needs.
  • A typical cause: the library is not included, or the routine you call is not in it.
  • It is reported while the program is being built, after translation, so no executable program is produced.
  • Have a goA linking error has just stopped your build. Can you still run the finished program anyway: yes or no?

    No.

    The error is reported while the program is being built, so no executable program is produced until it is corrected.

  • To correct it, make every separate routine available to the linker and call each one by its correct name.

The big picture

Programs often use code written separately, such as library routines. Linking joins the translated program to that code, and a linker does the joining. A linking error means that join failed. It is reported while the program is being built, after translation, so no executable program exists until it is corrected.

Key points

1Library routines are pre-written subroutines, stored separately so many programs can reuse them.
2Linking joins the translated program to the separately written code it uses; a linker does this.
3A linking error means that join failed, for example because a library is missing or a routine's name is wrong.
4It is reported during the build, after translation, so no executable program is produced until it is corrected.

Worked example

Problem

A build stops and prints: undefined reference to `average_marks'. The program should use a routine from a library called gradelib, and gradelib is included in the build. gradelib stores a routine called average_mark. What kind of error is this, and how is it corrected?

⚠ Watch out

Thinking a linking error is a typing mistake in your own lines, or something that goes wrong while the program is running. It is reported while the program is being built, after translation, because separately written code the program calls cannot be found and joined to it.

🧠

Memory hook

Translate, then link. If the link breaks, there is no program to run.

✓

Check yourself

Your program translates fine, but the build still cannot find a routine. Which stage failed, and can you run it? (Answer: linking, after translation. No executable program exists, so nothing runs.)

Flashcards

(11)
Why do programs use library routines?
To reuse pre-written subroutines instead of writing everything themselves.
What is a library?
A place where pre-written subroutines are stored so that many programs can reuse them.
What does linking do?
It joins the translated program to the separately written code it uses, making a single program that can be executed.
What is a linker?
The program that carries out the linking step.
What is a linking error?
The program cannot be joined to separately written code that it needs.
Name one cause of a linking error.
A library routine the program calls is missing or cannot be found, for example the library was not included.
When is a linking error reported?
During the build, once translation has finished.
What happens to the executable program when there is a linking error?
None is produced until the error is corrected.
How is a linking error corrected?
Make sure every separately written routine is available to the linker, and call each by its correct name.
Which comes first, translating or linking?
Translating. Linking joins code that has already been translated.
Can a perfectly written program have a linking error?
Yes. If code it calls from a library is not available to the linker, the pieces cannot be joined.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 16 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.