Linkers, Loaders & Executables
What is the most suitable use of Linux's dlopen function (the counterpart of Windows LoadLibrary)?
- AOpening and editing a program's source code
- BLoading a shared library needed at run time, such as a plug-in, and calling its functions
- 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.