title: Conflict between dynamic linking priority in OSX?
body: <p>There is a dynamic-linking-conflict between different libjpeg dynamic libraries on OSX. First there is a standard native libJPEG.dylib (in /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/). But if you are using MacPorts, you can also have a port-related libjpeg.dylib in (in /opt/local/lib). The latter may for example have been installed as a dependency for some other port.</p>
  
  <p>This creates a problem when you link against your system libJPEG (which is preferred). 
  Then if <code>/opt/local/lib</code> is in DYLD_LIBRARY_PATH, that path will be prioritised when searching for a dynamic lib, resulting in a runtime error when loading symbols:</p>
  
  <pre><code>dyld: Symbol not found: __cg_jpeg_resync_to_restart
   Referenced from:
  /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
   Expected in: /opt/local/lib/libJPEG.dylib
  in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
  Trace/BPT trap: 5
  </code></pre>
  
  <p>So I have two questions (likely related):</p>
  
  <ol>
  <li><p>What is a good way of solving the actual problem (removing <code>/opt/local/lib</code> from <code>DYLD_LIBRARY_PATH</code> obviously solves it but creates problems for other dependencies)?</p></li>
  <li><p>What other paths are searched for dynamic libs (I.e. Where is the "/System/Library" path specified) and why does DYLD_LIBRARY_PATH rank higher priority-wise?</p></li>
  </ol>