Linkers, Loaders & Executables

Which describes static linking?

  1. AThe code of the libraries used is copied into the executable
  2. BThe libraries are loaded and bound every time the program runs
  3. CAll processing is written in one source file without libraries
Show answer and explanation

Answer: A. The code of the libraries used is copied into the executable

With static linking, the linker extracts the needed functions from static libraries (.a files on Linux) and builds them into the executable. It runs even where the library is absent and needs no binding at start-up, but the executable grows and every program using the library carries its own copy. Fixes to the library are not picked up unless the program is rebuilt.

  • A. Correct. The executable runs on its own.
  • B. That is dynamic linking.
  • C. That is unrelated to whether libraries are used.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What is an advantage of dynamic linking (shared libraries)?
  2. A dynamically linked program copied to another computer fails to start. What is the most likely cause?
  3. When linking with a static library (.a file), what does the linker put into the executable?
  4. With the GNU linker, writing a static library before the object file that uses it, as in "gcc -lmylib main.o", can cause undefined-reference errors. Why?
  5. Which describes position-independent code (PIC)?