Linkers, Loaders & Executables
When linking with a static library (.a file), what does the linker put into the executable?
- AAll object files in the library
- BOnly the library's file name, with no code
- COnly the object files in the library that are needed to resolve undefined references
Show answer and explanation
Answer: C. Only the object files in the library that are needed to resolve undefined references
A static library is an archive bundling many object files. The linker extracts and includes only those object files that define symbols still lacking a definition. So even with a library containing many functions, such as the standard library, the executable grows only by the functions actually used.
- A. Including everything would bloat the executable.
- B. Recording only names is dynamic linking.
- C. Correct. Unused parts are left out.