I need to dynamically open a shared library lib.so
if a specific condition is met at runtime. The library contains ~700 functions and I need to load all their symbols.
A simple solution is to define the function pointers to all symbols contained in lib.so
, load the library using dlopen
and finally get the addresses of all symbols using dlsym
. However, given the number of functions, the code implementing this solution is very cumbersome.
I was wondering if a more elegant and concise solution exists, maybe with an appropriate use of macros for defining the function pointers. Thanks!
Refer to difference between dynamic loading and dynamic linking? , you may need dynamic linking instead of dynamic loading a shared library.