Linkers, Loaders & Executables

A dynamically linked program copied to another computer fails to start. What is the most likely cause?

  1. AThe executable contains all library code and is too large
  2. BDynamically linked programs are allowed to run only on the computer that built them
  3. CA required shared library is missing or only an incompatible version is installed
Show answer and explanation

Answer: C. A required shared library is missing or only an incompatible version is installed

A dynamically linked program uses the shared libraries on the computer where it runs. If a required library is absent, or only an older version lacking some functions is present, the dynamic linker cannot bind it and start-up fails. On Linux the ldd command shows which shared libraries a program needs and whether they are found. Some developers choose static linking deliberately to make distribution easier.

  • A. With dynamic linking, library code is not in the executable.
  • B. There is no such rule.
  • C. Correct. It depends on the libraries on the target system.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. When linking with a static library (.a file), what does the linker put into the executable?
  2. 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?
  3. Which describes position-independent code (PIC)?
  4. What is the role of the GOT (global offset table) used in shared libraries?
  5. When dynamic linking uses lazy binding through the PLT (procedure linkage table), which statement is correct?