title: In C/C++, how do I determine if a library is statically linked or not
body: <p>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.</p>
  <p>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.</p>
  <p>I would like to be able to improve/simplify matters by separating the GUI functionality of this library into a separate &quot;extension&quot; 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 &quot;stub&quot; functions that do nothing or return errors as appropriate. The two objects would inherit from a common pure virtual abstract base class.</p>
  <p>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.</p>
  <p>I have been thinking along the lines of implementing a function in the main library like this:</p>
  <pre><code>bool SupportsGUI() { return false; }
  </code></pre>
  <p>and then implementing the same function in the GUI support library like this:</p>
  <pre><code>bool SupportsGUI() { return true; }
  </code></pre>
  <p>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.</p>
  <p>I cannot figure out how to get this to work.</p>
  <p>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?</p>
  <p>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.</p>