title: OSX runtime dynamic library path search
body: <p>In Linux Ubuntu I can compile C++ source code with dynamic library and tell the gcc compiler where to find the .so lib file by setting environment variable <em>$LD_RUN_PATH</em> before compile. I would like to know is there a equivalent method for clang compiler in OSX to do such run time dynamic library path search?</p>
  
  <p>Thank you very much!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The duplicate link given below is not what I want!</p>
  
  <p>I would like to compile the search path for dylib into the executable. At runtime there should not be any path info set explicitly for <em>$DYLD_LIBRARY_PATH</em> environment path. Which is to say when you echo <em>$DYLD_LIBRARY_PATH</em> no path point to the dylib should be seen.</p>
  
  <p>I achieved this by using</p>
  
  <pre><code>otool -L &lt;executable&gt;
  </code></pre>
  
  <p>to read the search path in my executable.</p>
  
  <p>For any wrong or lack of search path, I use install_name_too to update or add the search path information.</p>
  
  <p>For me I am changing my original linking path. I use</p>
  
  <pre><code>install_name_tool -change &lt;old_path&gt; &lt;new_path&gt; &lt;executable&gt;
  </code></pre>
  
  <p>for link path setting. After this I am able to run the executable correctly link to the dylib without setting anything inside <em>$LD_LIBRARY_PATH</em> or <em>$LD_FALLBACK_LIBRARY_PATH</em>.</p>