title: How to compile source that uses dylib path on macOS Sierra from the shell
body: <p>I'm compiling some source code that requires some dylibs from other project that I have already built. I'm getting </p>
  
  <blockquote>
    <p>ld: symbol(s) not found for architecture x86_64`</p>
  </blockquote>
  
  <p>Whenever I execute</p>
  
  <pre class="lang-bash prettyprint-override"><code>g++ some_code.cpp -I/usr/local/include -o executable_binary
  </code></pre>
  
  <p>I know that <code>g++</code> is not able to find the compiled the dylibs (installed at <code>/usr/local/include</code>) since the error also mentions a lot of specific symbols that are part of the dylibs.</p>
  
  <p>I have already tried this:</p>
  
  <ol>
  <li>Executing <code>install_name_tool -id "@/usr/local/lib/requiredlib.dylib" /usr/local/lib/requiredlib.dylib</code></li>
  <li>Adding <code>-L/usr/local/lib</code> to the compilation options.</li>
  <li>Adding all the dylib paths explicitly to the compilation options.</li>
  <li>Try to add <code>DYLD_LIBRARY_PATH</code> unsuccessfully since Sierra doesn't allow to set that variable for security reasons.</li>
  </ol>
  
  <p>I know that it might possible to add <code>DYLD_LIBRARY_PATH</code> but that requires to disable SIP. I can do it by I do not want to if there is a cleaner way to do this.</p>
  
  <p>P.S.: I am trying to compile the tutorial examples for <a href="http://tulip.labri.fr/TulipDrupal/" rel="noreferrer">Tulip graph library</a>.</p>
  
  <p>The missing symbols are related to the the graph library I have installed. The error message is: </p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "tlp::saveGraph(tlp::Graph*, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, tlp::PluginProgress*)", referenced from:
        _main in tutorial001-02ee7e.o
    "operator&lt;&lt;(std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, tlp::Graph const*)", referenced from:
        _main in tutorial001-02ee7e.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <p>Whenever I do <code>ls /usr/local/lib/requiredlib.dylib</code> the all the compiled libraries from Tulip are there.</p>
  
  <p><code>g++ -v</code> produces:</p>
  
  <pre><code>Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 8.1.0 (clang-802.0.42)
  Target: x86_64-apple-darwin16.5.0
  Thread model: posix
  InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  </code></pre>
  
  <p>After doing <code>ls /usr/local/include/tulip/</code> I get the list of <code>*.h</code> files of the libraries I intend to use.</p>