I have a static library that provides some functionality. I have applications that use this library. Some of these applications are command line applications or run as daemons/services. Some of these applications are GUI applications.
The library offers functionality to provide GUI elements to allow it to be configured by the user. I build the library in two flavours; a GUI flavour and a CLI flavour. I then link the appropriate version to the application.
I would like to be able to improve/simplify matters by separating the GUI functionality of this library into a separate "extension" library that provides GUI support. My plan is that at runtime the main library somehow detects the presence of the GUI support library. If present then it instantiates an object from the GUI library that provides the necessary functionality, and if not it instantiates an object from itself that provides the same APIs as "stub" functions that do nothing or return errors as appropriate. The two objects would inherit from a common pure virtual abstract base class.
This must be done at runtime because I want to be able to link exactly the same binary of the main library to both CLI and GUI applications, and not rely on compile time switches which, by definition, result in differing binaries.
I have been thinking along the lines of implementing a function in the main library like this:
bool SupportsGUI() { return false; }
and then implementing the same function in the GUI support library like this:
bool SupportsGUI() { return true; }
and then, when linking the application, somehow force the linker to resolve the link to use the one from the GUI support library if present.
I cannot figure out how to get this to work.
Assuming that both libraries are static libraries how can I, at runtime, determine from one library whether the linking application has also linked the other?
Alternatively, how can I, at link time, override a set of functions implemented in one library with an equivalent set of functions implemented in a separate library.