Qt:在Mac上的链接框架:使用rpath

费利克斯

我想用Qt创建一个自定义框架。我能够创建框架本身,但是Qt在运行时找不到框架:

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

原因很简单:二进制文件不知道在哪里寻找框架。

我在二进制文件上使用了otool并看到了以下内容:

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)

因此,我的问题如下(有关更多详细信息,请参见下面的内容):如何告诉qmake将我的库的路径设置为:

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

有没有办法用qmake做到这一点?我确实知道如何使用来更改此设置install_name_tool,但我想将其直接添加到.pro文件中。


到目前为止,我所做的是:

我修改了我的pro文件,将其更改为二进制文件的rpath,以包括在构建时库所在的路径:

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)

这样,我可以简单地修改发行版的rpath,而不必使用install_name_tool但是,为了使它起作用,我需要将第一行更改为:

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

在我的应用程序专业文件中,我指定了以下内容:

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

最后缺少的部分是如何添加@rpath/谢谢你的帮助。

费利克斯

感谢@peppe的评论中的链接,我得以解决此问题:

我必须添加

QMAKE_LFLAGS_SONAME = -Wl,-install_name,@rpath/

图书馆专业文件。Qt@rpath/QSettingsDialog.framework/Versions/0/QSettingsDialog在创建对框架的引用时自动使用这种方式

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章