title: Link only needed symbols when compiling an executable with a Shared Library
body: <p>I'm working on a heavy project that has a lot of static libraries that are interdependent. Furthermore some symbols are redundant between some libraries, with different implementations. My goal is to make the project work with shared libraries.</p>
  
  <p>I tried to compile an executable with one of my shared libs, and <strong>I get undefined symbols errors on functions that my executable isn't using</strong>. After some research I understood that the dynamic linker works in very different ways than the static linker. If I understood right, when linking a shared library, all symbols need to be resolved as the whole library is loaded in the memory.</p>
  
  <p>A simple workaround would be to add all the dependencies of my libraries when compiling the executable. But they're so full of dependencies that this sometimes means adding 10+ libraries to the command line, and this would be for something like a hundred executable.</p>
  
  <p>So far I tried using <code>-Wl,--as-needed</code>, <code>-Wl,--unresolved-symbols=ignore-in-shared-libs</code>, and opening the shared object with <code>dlopen</code> to get the function I want with <code>dlsym</code>. But all of these methods fail at one point or another.</p>
  
  <p>My question is: <strong>Are you forced to resolve every undefined symbol of a dynamic library when linking it against an executable ?</strong></p>