Reputation: 1337
What is the main difference between using a .so file a link time or using it at run time (dlopen() etc) ?
Upvotes: 1
Views: 1591
Reputation: 22552
At link time the compiler will only check that the symbols are available in the library and will specify which library to link against later (in case you are linking against multiple libraries providing the same symbol)
The header file will only tell the compiler of what function prototypes are available and (depending on the programming language used) how to translate them into symbols. e.g. C++ extern "C"
.
If you are linking against a library then the linker will create a global address translation table in the executable which will be populated with the symbol addresses at runtime when the library is loaded. If you are opening the library with dlopen
then you are responsible of creating variables holding the symbol pointers yourself via dlsym
, but it allows you more flexibility like e.g. changing those during runtime, loading plugins or other functions that are unavailable at compile time.
Upvotes: 3