2

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:

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

The reason is simple: The binary does not know where to look for the framework.

I used otool on the binary and saw this:

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)

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:

@rpath/QSettingsDialog.framework/Versions/0/QSettingsDialog (compatibility version 0.1.0, current version 0.1.2)

Is there even a way to do this with qmake? I do know how to change this with the install_name_tool, but I would like to add it to the .pro file directly.


What I did so far:

I modified my pro file to change to rpath of the binary to include the path where the library is located at build-time:

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)

This way I can simply modify the rpath for a release without having to use the install_name_tool. However, for this to work, I need to change the first line to:

@rpath/QSettingsDialog.framework/Versions/0/QSettingsDialog (compatibility version 0.1.0, current version 0.1.2)

In my pro file for the application, i specified the following:

mac {
    QMAKE_LFLAGS += -F$$OUT_PWD/../../QSettingsDialog/
    QMAKE_LFLAGS += '-Wl,-rpath,\'$$OUT_PWD/../../QSettingsDialog\''
    LIBS += -F$$OUT_PWD/../../QSettingsDialog/ -framework QSettingsDialog
}

The last missing piece is how to add the @rpath/. Thanks for your help.

Felix
  • 6,885
  • 1
  • 29
  • 54
  • 3
    Maybe take a look at the hacks that Qt Creator does? Cf. https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/qtcreatorlibrary.pri and https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/rpath.pri – peppe Jul 08 '16 at 20:40
  • Thanks, these two files came in very handy and helped me to solve the problem. – Felix Jul 08 '16 at 21:02
  • @Felix Can you please tell how to do with install_name_tool? Please have a look in this question : https://stackoverflow.com/questions/46088104/adding-external-libraries-deploying-qt-app-mac-osx – arqam Sep 07 '17 at 12:55

1 Answers1

2

Thanks to the links in the comment of @peppe, I was able to solve the problem:

I had to add

QMAKE_LFLAGS_SONAME = -Wl,-install_name,@rpath/

to the libraries pro file. This way Qt automatically uses @rpath/QSettingsDialog.framework/Versions/0/QSettingsDialog when creating the reference to the framework.

Felix
  • 6,885
  • 1
  • 29
  • 54