title: Defining Framework path relative to executable in gnu/clang compiler on mac
body: <p>I'm trying to compile a simple c++ test program with the <a href="https://www.libsdl.org/download-2.0.php" rel="nofollow noreferrer">SDL2 Framework</a> on mac 10.9.5 with clang++ 5.1.</p>
  <p>I'm trying to understand how to compile with frameworks manually in gnu/clang, so please refrain from answers that would require Xcode.</p>
  <br />
  <h1>Project layout</h1>
  <pre><code>Project/
  |
  |-- Output/
  |   |-- &lt;Unix Executable File&gt;
  |   |-- SDL2.framework
  |
  |-- Source/
  |   |-- main.cpp
  |
  |-- Frameworks/
  |   |-- SDL2.framework
  </code></pre>
  <p>Where main.cpp simply contains:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;SDL2/SDL.h&gt;
  
  int main(int, char**) {
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
      std::cout &lt;&lt; &quot;SDL_Init Error: &quot; &lt;&lt; SDL_GetError() &lt;&lt; std::endl;
      return 1;
    }
    std::cout &lt;&lt; &quot;SDL LOADED CORRECTLY!&quot; &lt;&lt; std::endl;
    SDL_Quit();
    return 0;
  }
  </code></pre>
  <p>And SDL2.framework is from the <a href="https://www.libsdl.org/download-2.0.php" rel="nofollow noreferrer">2.0.3 Mac Development Library</a>.</p>
  <br />
  <h1>Compiling</h1>
  <p>I can successfully compile and link with clang:</p>
  <pre><code>clang++ -framework SDL2 -FFrameworks Source/main.cpp -o Output/main_test
  </code></pre>
  <p>Using the <code>-F</code> preprocessor flag to manually add the <code>Frameworks</code> directory to the search path for Framework include files.</p>
  <br />
  <h1>Running</h1>
  <p>The resulting executable runs correctly if <code>SDL2.framework</code> exists in the Global frameworks directory, <code>/Library/Frameworks/</code>:</p>
  <pre><code>$ sudo cp -R Frameworks/SDL2.framework/ /Library/Frameworks/SDL2.framework/
  $ ./Output/main_test
  SDL LOADED CORRECTLY!
  </code></pre>
  <p>However I would prefer it if the executable used the <code>SDL2.framework</code> in the Output directory instead of requiring one in the Global frameworks directory.</p>
  <p>But without the global framework the executable no longer runs:</p>
  <pre><code>$ sudo rm -rf /Library/Frameworks/SDL2.framework/
  $ sudo cp -R Frameworks/SDL2.framework/ Output/SDL2.framework/
  $ ./Output/main_test
  dyld: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
    Referenced from: /Users/Jo/Desktop/Temp_Project/./Output/main_test
    Reason: image not found
  Trace/BPT trap: 5
  </code></pre>
  <br />
  <h1>Question</h1>
  <p>Is <code>@rpath</code> the path from where the executable is being run? In which case, why is it not able to find it? As far as I can tell the files needed are in the correct location:</p>
  <pre><code>$ ls -l Output/ 
  total 32
  drwxr-xr-x@ 6 Jo  staff    204 Mar 15  2014 SDL2.framework
  -rwxr-xr-x  1 Jo  staff  15252 Jun 24 17:35 main_test
  
  $ ls -l Output/SDL2.framework/Versions/A/
  total 3448
  drwxr-xr-x@ 56 Jo  staff     1904 Mar 15  2014 Headers
  drwxr-xr-x@  3 Jo  staff      102 Mar 15  2014 Resources
  -rwxr-xr-x@  1 Jo  staff  1762208 Mar 15  2014 SDL2
  drwxr-xr-x@  3 Jo  staff      102 Mar 15  2014 _CodeSignature
  </code></pre>
  <p>With the following <code>otool</code> Library output:</p>
  <pre><code>otool -L Output/main_test 
  Output/main_test:
      @rpath/SDL2.framework/Versions/A/SDL2 (compatibility version 1.0.0, current version 3.1.0)
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
  </code></pre>
  <br />
  <h1>TL;DR</h1>
  <p>Is there a step that I am missing when compiling that would enable the executable to use for the Framework in a location relative to it instead of an absolute global one?</p>
  <p>It seems like <a href="https://stackoverflow.com/questions/27506450/clang-change-dependent-shared-library-install-name-at-link-time">this Question</a> could be related but as of this post it has yet to be answered.</p>