Need help from an expert?
The world’s top online tutoring provider trusted by students, parents, and schools globally.
Linkers deal with multiple object files by combining them into a single executable file and resolving symbol references.
Linkers, also known as link editors, play a crucial role in the process of program compilation. When a program is divided into multiple source files, each file is compiled into an object file. These object files contain machine code, but they also contain unresolved symbols - references to functions or variables that are defined in other object files. The linker's job is to take these separate object files and combine them into a single executable file, resolving all the symbol references in the process.
The linker starts by examining each object file to build a symbol table. This table contains the names and locations of all the functions and variables defined in the object files. The linker then goes through each object file again, this time looking for unresolved symbols. For each unresolved symbol, the linker checks the symbol table to find where that symbol is defined. It then replaces the unresolved symbol with the correct address.
In addition to resolving symbol references, the linker also has to arrange the different sections of the object files into a logical order in the final executable. For example, all the code sections from the different object files might be placed together, followed by all the data sections. The linker also has to ensure that any initialisation code is placed at the start of the executable, so that it runs before anything else.
Sometimes, the linker might encounter the same symbol defined in multiple object files. This is known as a 'linker error', and it usually indicates a mistake in the program. For example, the programmer might have accidentally defined the same function twice. In this case, the linker will report the error and stop the linking process.
In summary, the linker is a vital tool in the process of turning source code into an executable program. It takes multiple object files, each with their own unresolved symbols, and combines them into a single executable file where all the symbols have been resolved.
Study and Practice for Free
Trusted by 100,000+ Students Worldwide
Achieve Top Grades in your Exams with our Free Resources.
Practice Questions, Study Notes, and Past Exam Papers for all Subjects!
The world’s top online tutoring provider trusted by students, parents, and schools globally.