title: How to specify preference of library path?
body: <p>I'm compiling a c++ program using <code>g++</code> and <code>ld</code>. I have a <code>.so</code> library I want to be used during linking. However, a library of the same name exists in <code>/usr/local/lib</code>, and <code>ld</code> is choosing that library over the one I'm directly specifying. How can I fix this?</p>
  
  <p>For the examples below, my library file is <code>/my/dir/libfoo.so.0</code>. Things I've tried that don't work:</p>
  
  <ul>
  <li>my g++ command is <code>g++ -g -Wall -o my_binary -L/my/dir -lfoo bar.cpp</code></li>
  <li>adding <code>/my/dir</code> to the beginning or end of my <code>$PATH</code> en` variable</li>
  <li>adding <code>/my/dir/libfoo.so.0</code> as an argument to g++</li>
  </ul>