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.
- /* main.c */
- #include <stdio.h>
- #include "shapes.h"
- int main(void) {
- double r = 3.0;
- printf("Area: %.2f\n", circle_area(r));
- return 0;
- }
- $ 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 · 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.
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
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?
What is a library?
What does linking do?
What is a linker?
What is a linking error?
Name one cause of a linking error.
When is a linking error reported?
What happens to the executable program when there is a linking error?
How is a linking error corrected?
Which comes first, translating or linking?
Can a perfectly written program have a linking error?
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 postedMore Eduqas GCSE Computer Science topics
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.