简体   繁体   中英

Qt: Linking Framework on Mac: using rpath

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM