title: Qt: Linking Framework on Mac: using rpath
body: <p>I want to create a custom framework with Qt. I am able to create the framework itself, but Qt fails to find the framework when run:</p>
  
  <pre><code>dyld: Library not loaded: QSettingsDialog.framework/Versions/0/QSettingsDialog
    Referenced from: /Users/sky/QtProjects/build-QSettingsDialog-Desktop_Qt_5_7_0_clang_64bit-Debug/Examples/SimpleExample/SimpleExample.app/Contents/MacOS/SimpleExample
    Reason: image not found
  </code></pre>
  
  <p>The reason is simple: The binary does not know where to look for the framework.</p>
  
  <p>I used otool on the binary and saw this:</p>
  
  <pre><code>otool -L Examples/SimpleExample/SimpleExample.app/Contents/MacOS/SimpleExample 
  Examples/SimpleExample/SimpleExample.app/Contents/MacOS/SimpleExample:
      QSettingsDialog.framework/Versions/0/QSettingsDialog (compatibility version 0.1.0, current version 0.1.2)
      @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.7.0, current version 5.7.0)
      @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.7.0, current version 5.7.0)
      @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.7.0, current version 5.7.0)
      /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
      /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
  </code></pre>
  
  <p>So, my question is as follows (For more details check the stuff below):
  How can tell qmake to set the path for my library to: </p>
  
  <pre><code>@rpath/QSettingsDialog.framework/Versions/0/QSettingsDialog (compatibility version 0.1.0, current version 0.1.2)
  </code></pre>
  
  <p>Is there even a way to do this with qmake? I do know how to change this with the <code>install_name_tool</code>, but I would like to add it to the .pro file directly.</p>
  
  <hr>
  
  <p>What I did so far:</p>
  
  <p>I modified my pro file to change to rpath of the binary to include the path where the library is located at build-time:</p>
  
  <pre><code>otool -l Examples/SimpleExample/SimpleExample.app/Contents/MacOS/SimpleExample 
  Load command 22
            cmd LC_RPATH
        cmdsize 136
           path /Users/sky/QtProjects/build-QSettingsDialog-Desktop_Qt_5_7_0_clang_64bit-Debug/Examples/SimpleExample/../../QSettingsDialog (offset 12)
  Load command 23
            cmd LC_RPATH
        cmdsize 48
           path /Users/sky/Qt/5.7/clang_64/lib (offset 12)
  </code></pre>
  
  <p>This way I can simply modify the rpath for a release without having to use the <code>install_name_tool</code>. However, for this to work, I need to change the first line to:</p>
  
  <pre><code>@rpath/QSettingsDialog.framework/Versions/0/QSettingsDialog (compatibility version 0.1.0, current version 0.1.2)
  </code></pre>
  
  <p>In my pro file for the application, i specified the following:</p>
  
  <pre><code>mac {
      QMAKE_LFLAGS += -F$$OUT_PWD/../../QSettingsDialog/
      QMAKE_LFLAGS += '-Wl,-rpath,\'$$OUT_PWD/../../QSettingsDialog\''
      LIBS += -F$$OUT_PWD/../../QSettingsDialog/ -framework QSettingsDialog
  }
  </code></pre>
  
  <p>The last missing piece is how to add the <code>@rpath/</code>. Thanks for your help.</p>