title: Overriding functions from dynamic libraries
body: <p>Hello I have a program with a global function that I'd like to customize at run time. Say, there are many versions of function foo() scattered over shared libraries. Now, based on system configuration detected at run time I'd like to use function from appropriate library.</p>
  
  <p>File loader.cpp:</p>
  
  <pre><code>#include &lt;dlfcn.h&gt;
  #include &lt;iostream&gt;
  
  void __attribute__((weak)) foo();
  
      int main(int argc, char *argv[])
      {
          void* dl = dlopen("./other.so", RTLD_NOW | RTLD_GLOBAL);
          if (!dl)
          {
              std::cerr &lt;&lt; dlerror() &lt;&lt; std::endl;
              return 1;
          }
          if (foo)
          {
              foo();
          }
          else
          {
              std::cerr &lt;&lt; "No foo?" &lt;&lt; std::endl;
          }
          dlclose(dl);
          return 0;
      }
  </code></pre>
  
  <p>File other.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  void foo()
  {
      std::cout &lt;&lt; "FOO!" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>I compile the program with</p>
  
  <pre><code>g++ -Wall -fPIC -o loaded loader.cpp -ldl
  g++ -Wall -fPIC -shared -o other.so  other.cpp 
  </code></pre>
  
  <p>However the weak symbol is not overriden. Any hints?</p>