【问题标题】:Qt Mac Application Failed to Create Self-contained App Bundle (Qt Creator Build)Qt Mac 应用程序无法创建自包含 App Bundle (Qt Creator Build)
【发布时间】:2016-08-24 15:49:47
【问题描述】:

我正在使用 Qt Creator 3.6.1Qt 5.6.0 (Clang 7.0 (Apple), 64 bit),在尝试创建应用程序包以进行部署时遇到了一些问题。

注意:应用名称叫bibi

  1. Qt Creatorbuild-bibi-Desktop_Qt_5_6_0_clang_64bit-Release/文件夹下成功生成bibi.app
  2. bibi.app 未能在另一台 Mac 上成功链接 Qt
  3. macdeployqt 没有解决问题

以下是详细信息:

在另一台 Mac 上运行 bibi.app 时出现错误截图:

otool

> otool -L build-bibi-Desktop_Qt_5_6_0_clang_64bit-Release/bibi.app/Contents/MacOS/bibi
build-bibi-Desktop_Qt_5_6_0_clang_64bit-Release/bibi.app/Contents/MacOS/bibi:
    @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.6.0, current version 5.6.0)
    @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.6.0, current version 5.6.0)
    @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.6.0, current version 5.6.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)

ma​​cdeployqt

> which macdeployqt
/Users/<myusername>/Qt/5.6/clang_64/bin/macdeployqt
> macdeployqt bibi.app
> otool -L bibi.app/Contents/MacOS/bibi
bibi.app/Contents/MacOS/bibi:
    @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.6.0, current version 5.6.0)
    @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.6.0, current version 5.6.0)
    @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.6.0, current version 5.6.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)

树 bibi.app

bibi.app
├── Contents
│   ├── Frameworks
│   │   ├── QtCore.framework
│   │   │   ├── QtCore -> Versions/Current/QtCore
│   │   │   ├── Resources -> Versions/Current/Resources
│   │   │   └── Versions
│   │   │       ├── 5
│   │   │       │   ├── QtCore
│   │   │       │   └── Resources
│   │   │       │       └── Info.plist
│   │   │       └── Current -> 5
│   │   ├── QtDBus.framework
│   │   │   ├── QtDBus -> Versions/Current/QtDBus
│   │   │   ├── Resources -> Versions/Current/Resources
│   │   │   └── Versions
│   │   │       ├── 5
│   │   │       │   ├── QtDBus
│   │   │       │   └── Resources
│   │   │       │       └── Info.plist
│   │   │       └── Current -> 5
│   │   ├── QtGui.framework
│   │   │   ├── QtGui -> Versions/Current/QtGui
│   │   │   ├── Resources -> Versions/Current/Resources
│   │   │   └── Versions
│   │   │       ├── 5
│   │   │       │   ├── QtGui
│   │   │       │   └── Resources
│   │   │       │       └── Info.plist
│   │   │       └── Current -> 5
│   │   ├── QtPrintSupport.framework
│   │   │   ├── QtPrintSupport -> Versions/Current/QtPrintSupport
│   │   │   ├── Resources -> Versions/Current/Resources
│   │   │   └── Versions
│   │   │       ├── 5
│   │   │       │   ├── QtPrintSupport
│   │   │       │   └── Resources
│   │   │       │       └── Info.plist
│   │   │       └── Current -> 5
│   │   └── QtWidgets.framework
│   │       ├── QtWidgets -> Versions/Current/QtWidgets
│   │       ├── Resources -> Versions/Current/Resources
│   │       └── Versions
│   │           ├── 5
│   │           │   ├── QtWidgets
│   │           │   └── Resources
│   │           │       └── Info.plist
│   │           └── Current -> 5
│   ├── Info.plist
│   ├── MacOS
│   │   └── bibi
│   ├── PkgInfo
│   ├── PlugIns
│   │   ├── imageformats
│   │   │   ├── libqdds.dylib
│   │   │   ├── libqgif.dylib
│   │   │   ├── libqicns.dylib
│   │   │   ├── libqico.dylib
│   │   │   ├── libqjpeg.dylib
│   │   │   ├── libqtga.dylib
│   │   │   ├── libqtiff.dylib
│   │   │   ├── libqwbmp.dylib
│   │   │   └── libqwebp.dylib
│   │   ├── platforms
│   │   │   └── libqcocoa.dylib
│   │   └── printsupport
│   │       └── libcocoaprintersupport.dylib
│   └── Resources
│       ├── empty.lproj
│       └── qt.conf
└── Icon\r

38 directories, 32 files

谢谢。

问题已解决

感谢scott,问题解决了。以下是我未能成功创建自包含应用程序包的原因:

  • otool -L 没有解析 @rpath,我很困惑,因为它总是返回相同的输出
  • 缺乏测试捆绑包是否已经包含所有框架的方法

简而言之,问题可以通过使用Scott的otool-rpathlsof,或者设置DYLD_PRINT_LIBRARIESDYLD_PRINT_TO_FILE来解决。而且,我已经写了一个注释here

【问题讨论】:

    标签: macos qt dyld otool macdeployqt


    【解决方案1】:

    假设您使用了qt-unified-max-x64-online.dmg 安装程序并将Qt 安装到$HOME/Qt。您可以使用以下方式构建您的项目:

    cd MY-QT-PROJECT
    QT_BIN_DIR=$HOME/Qt/5.6/clang_64/bin
    make clean
    $QT_BIN_DIR/qmake -config release
    make -j$(getconf NPROCESSORS_ONLN)
    

    这会创建一个应用程序包,但它不会在普通用户的机器上运行。

    查看包中埋藏的 Mach-O 可执行文件中的 RPATH:

    otool-rpath ./*.app/Contents/MacOS/*
    /Users/user/Qt/5.6/clang_64/lib
    

    我正在使用我自己在此处编写的一个小型 otool-rpath 脚本,用于说明目的。

    RPATH 加上上面otool -L 输出中列出的安装名称使动态链接器dyld/Users/user/Qt/5.6/clang_64/lib 下查找Qt 框架。因此,它适用于未在同一位置安装 Qt 的用户。

    要改变这一点,请运行 Qt 的 macdeployqt 工具:

    $QT_BIN_DIR/macdeployqt ./*.app -verbose=3 -always-overwrite -appstore-compliant
    

    查看示例macdeployqt 日志here

    macdeployqt 创建独立的应用程序包。观察可执行文件中的 RPATH 如何从 /Users/user/Qt/5.6/clang_64/lib 更改为 @executable_path/../Frameworks

    otool-rpath ./*.app/Contents/MacOS/*
    @executable_path/../Frameworks
    

    @executable_path 做了显而易见的事情,并在运行时由dyld 扩展为bibi.app/Contents/MacOS。可执行文件中的 RPATH 和安装名称一起使捆绑包内的动态链接在运行时起作用。

    进一步阅读

    参考文献

    关键字:“RPATH”、“安装名称”、“Mach-O 动态链接”。

    请注意,ELF 中的 RPATH 具有细微差别的语义。

    【讨论】:

      猜你喜欢
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多