Which one among the following is used to combine several object modules and libraries to a single executable program ?
- (a)Interpreter
- (b)Compiler
- (c)Linker
- (d)Loader
Correct — C, (c) Linker. Combining object modules and libraries into one executable file is the definition of what a linker does, and no other program in the chain does it. Follow a program from source to running process and each option finds its own place. A programmer writes several source files. The compiler translates each of them separately into an object module — machine code, but incomplete, because a routine called in one file may be defined in another or in a library and the compiler has no way of knowing where it will finally sit. Each object module therefore carries a table of the symbols it defines and a list of the symbols it needs from elsewhere. The linker takes that pile of object modules together with the library modules they call, and performs two jobs. First it resolves the external references — for every symbol a module needs, it finds the module or library that defines it and fills in the address, and it is the linker that reports an 'undefined reference' when nothing supplies one. Second it relocates: it lays the modules out in one address space and adjusts every address inside them so that the pieces refer to each other correctly in their new positions. The output is a single executable file. That is precisely what the stem describes. The distinction the item is really testing is between the linker and the loader, which candidates habitually merge. The linker works on files and produces a file; the loader works on memory and produces a running process. Linking happens once, before the program is distributed; loading happens every time the program is started. Two refinements worth knowing, because they explain why the boundary looks blurred in practice. Static linking copies the needed library code into the executable, which makes the file self-contained but larger, and means a corrected library requires the program to be linked again. Dynamic linking instead records the name of the shared library, and the binding is completed at load time or even at first call by a dynamic linker that is itself part of the loading machinery — which is what a Windows dynamic link library or a shared object file on a Unix-like system is for. Even so, the program that combines object modules and libraries into an executable is the linker, and that is the answer here.
- (a)Interpreter — An interpreter never produces an executable at all, so it cannot combine modules into one. It reads the source program one statement at a time, translates that statement and immediately carries it out, then moves to the next — so translation and execution are interleaved and nothing is saved for later. That is why an interpreted program needs the interpreter present every time it runs, why it is generally slower than compiled code, and why an error deep in the program is discovered only when execution reaches it. There is no object module in this model and therefore nothing for a linking step to do.
- (b)Compiler — The compiler is the step immediately before the linker and produces the very things the linker combines, but it does not combine them. It reads one complete source file, checks it, and translates it into a single object module, reporting all the errors it finds in that file at once. Because it looks at one translation unit at a time, it cannot know the final address of a routine defined in another file, so it leaves those references unresolved for the linker to fill in. The confusion is encouraged by everyday language, in which 'compiling a program' loosely describes the whole build; strictly, compilation ends at the object module.
- (d)Loader — The loader is the step immediately after the linker, and it acts on the finished executable rather than on object modules. Its job is to bring that executable file from secondary storage into main memory, allocate the space it needs, adjust addresses if the program has been placed somewhere other than where it expected, and transfer control to its first instruction. It is part of the operating system and it runs every time a program is started, whereas linking is done once. Loading a single executable into memory is not combining several modules into one, so this option describes a different stage.
The route from a written program to a running one passes through four distinct system programs, and each has one job. A compiler translates a whole source file in a high-level language into an object module in machine code, reporting errors for the file as a unit; an assembler does the same for a program written in assembly language. A linker takes the object modules and the library modules together, resolves the external symbol references between them, relocates their contents into one address space and writes a single executable file. A loader brings that executable into main memory when it is run and hands control to it. An interpreter belongs to a different model altogether, translating and executing statement by statement without producing an object module or an executable. The linker's two functions, symbol resolution and relocation, are what allow separate compilation to exist — a large program can be split across many files, each compiled and recompiled on its own, and only the linking step has to see them all. The same mechanism allows libraries: code written once and compiled once can be attached to any number of later programs without being recompiled.
System-software vocabulary is a standing item in the EO/AO computers block, and the compiler-linker-loader-interpreter set is the part of it that is asked most often, usually as a one-line definition to be matched to a name. The habit rewarded is holding the pipeline in order — source, compiler, object module, linker, executable, loader, memory — because every question in this family names one arrow in that chain and asks which program draws it. Note that the booklet prints a space before the question mark, which is its style throughout the paper.
- A linker combines object modules and library modules into a single executable program.
- The linker's two functions are symbol resolution, which fills in addresses for external references, and relocation, which adjusts addresses when modules are laid out together.
- A compiler translates one complete source file into one object module and reports the errors in that file together.
- A loader brings the executable from storage into main memory and starts it; it runs at every execution, whereas linking is done once.
- An interpreter translates and executes one statement at a time and produces no object module or executable.
- An assembler is the compiler's counterpart for assembly language, producing an object module from assembly source.
- Static linking copies library code into the executable; dynamic linking records the library's name and binds it at load or first call.
- An 'undefined reference' message comes from the linker, because it is the linker that must find a definition for every symbol used.
- Swapping the linker and the loader, which is the single commonest error in this family — one combines files, the other fills memory.
- Believing the compiler produces the executable directly; it produces an object module, which still has unresolved references.
- Expecting an interpreted language to have a linking step at all.
- Assuming dynamic linking means the loader does the linking; the binding is performed by a dynamic linker, and the linker's role has moved in time, not disappeared.
This theme appears in EO/AO papers as a definition-to-name item like this one, as a matching item pairing four system programs with four descriptions, or as a question about the order of the stages in producing a running program. Learn the pipeline as a sentence and the whole family follows: the compiler translates a file, the linker joins the files, the loader puts the result in memory, and the interpreter does without all three.
No directly related past PYQ was found.
- practice — not a real PYQ
Which one of the following brings an executable program from secondary storage into main memory for execution ?
- (a)Compiler
- (b)Linker
- (c)Loader
- (d)Assembler
Answer(c) Loader
- practice — not a real PYQ
A program that translates and executes a source program one statement at a time is called :
- (a)An assembler
- (b)An interpreter
- (c)A linker
- (d)A cross compiler
Answer(b) An interpreter