Linkers, Loaders & Executables

What is the most suitable use of Linux's dlopen function (the counterpart of Windows LoadLibrary)?

  1. AOpening and editing a program's source code
  2. BLoading a shared library needed at run time, such as a plug-in, and calling its functions
  3. COpening a file to read and write its data
Show answer and explanation

Answer: B. Loading a shared library needed at run time, such as a plug-in, and calling its functions

With ordinary dynamic linking, the shared libraries are fixed at start-up. dlopen lets a running program load a library by name, fetch a function's address with dlsym and call it. Because the library can be chosen by configuration or by the user, this is commonly used for plug-in systems and for optional features used only when available.

  • A. It has nothing to do with editing source.
  • B. Correct. It loads at the moment of need rather than at start-up.
  • C. Ordinary files are opened with fopen or open.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. When 100 processes use the same shared library, how is physical memory used?
  2. Disassembling an object file shows that an instruction calling the external function printf has a placeholder target such as 0. When is the correct value filled in?
  3. What is the role of a linker script used in embedded development?
  4. On a microcontroller without an OS, what does the start-up code do right after power-on before calling main?
  5. What is the difference between "sections" and "segments" in an ELF file?