title: Change library load order at run time (like LD_PRELOAD but during execution)
body: <p>How do I change the library a function loads from during run time?</p>
  
  <p>For example, say I want to replace the standard <code>printf</code> function with something new, I can write my own version and compile it into a shared library, then put "LD_PRELOAD=/my/library.so" in the environment before running my executable.</p>
  
  <p>But let's say that instead, I want to change that linkage from within the program itself. Surely that must be possible... right?</p>
  
  <p><strong>EDIT</strong><br>
  And no, the following doesn't work (but if you can tell me how to MAKE it work, then that would be sufficient).</p>
  
  <pre><code>void* mylib = dlopen("/path/to/library.so",RTLD_NOW);
  printf = dlsym(mylib,"printf");
  </code></pre>