尝试在OSX上部署.app包

时间:2012-05-23 04:56:21

标签: c++ qt deployment

刚刚完成以下教程:http://qt-project.org/doc/qt-4.8/deployment-mac.html#the-bundle

当我在我的应用上运行otool时,它看起来像这样:

qjson.framework/Versions/0/qjson (compatibility version 0.7.0, current version 0.7.1)
libboost_date_time.dylib (compatibility version 0.0.0, current version 0.0.0)
libQt.Shared.1.dylib (compatibility version 1.0.0, current version 1.0.0)
libQt.Framework.1.dylib (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.1)
@executable_path/../Frameworks/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.1)
@executable_path/../Frameworks/QtNetwork.framework/Versions/4/QtNetwork (compatibility version 4.8.0, current version 4.8.1)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)

在我这样做之前,它运行良好并指向了这个:

    /Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.1)
/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.1)
/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtNetwork.framework/Versions/4/QtNetwork (compatibility version 4.8.0, current version 4.8.1)

现在,当我打开我的应用程序时,它会立即崩溃。当我尝试在终端中打开它时,我得到以下问题:

objc[44337]: Class QNSImageView is implemented in both 
/Users/me/MyApp/MyApp.app/Contents/MacOS/./../Frameworks/QtGui.framework/Versions/4/QtGui and /Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/QtGui. One of the two will be used. Which one is undefined.

由“段错误”完成

我怎样才能让它不冲突?我试过运行Qts部署脚本,但这也不起作用。我做错了什么?

编辑:

我尝试再次使用他们的脚本,这次IDid以下内容:

macdeployqt MyApp.app -dmg -no-plugins

这会在我的应用程序中创建一个运行的.dmg。现在的问题是没有任何反应,当我在终端中运行时,我收到了这个错误:

QEventLoop: Cannot be used without QApplication
QEventLoop: Cannot be used without QApplication

我的eventloop发生了什么?我的应用程序没有任何改变,因为我从finder中完美地运行它,当我部署它并从deplyod版本运行它。毫无意义

更新:现在我尝试删除旧应用并使用QtCreator从头开始构建它。然后我做了以下事情:

bash-3.2$ /Users/me/Downloads/macdeployqt-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Release/macdeployqt/macdeployqt MyApp.app
copied "/Library/Frameworks/qjson.framework/Versions/0/qjson" to "MyApp.app/Contents/Frameworks/qjson.framework/Versions/0/qjson" 
copied "/usr/lib/libboost_date_time.dylib" to "MyApp.app/Contents/Frameworks//libboost_date_time.dylib" 
copied "/usr/lib/libQt.Shared.1.dylib" to "MyApp.app/Contents/Frameworks//libQt.Shared.1.dylib" 
copied "/usr/lib/libQt.Framework.My.1.dylib" to "MyApp.app/Contents/Frameworks//libQt.Framework.My.1.dylib" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/QtGui" to "MyApp.app/Contents/Frameworks/QtGui.framework/Versions/4/QtGui" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Resources/qt_menu.nib/classes.nib" to "MyApp.app/Contents/Frameworks/QtGui.framework/Resources/qt_menu.nib/classes.nib" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Resources/qt_menu.nib/info.nib" to "MyApp.app/Contents/Frameworks/QtGui.framework/Resources/qt_menu.nib/info.nib" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Resources/qt_menu.nib/keyedobjects.nib" to "MyApp.app/Contents/Frameworks/QtGui.framework/Resources/qt_menu.nib/keyedobjects.nib" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/QtCore" to "MyApp.app/Contents/Frameworks/QtCore.framework/Versions/4/QtCore" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtNetwork.framework/Versions/4/QtNetwork" to "MyApp.app/Contents/Frameworks/QtNetwork.framework/Versions/4/QtNetwork" 
copied "/Users/me/QtSDK1.2.1/Desktop/Qt/4.8.1/gcc/lib/QtXml.framework/Versions/4/QtXml" to "MyApp.app/Contents/Frameworks/QtXml.framework/Versions/4/QtXml" 

Deploying plugins from "/usr/plugins"
Created configuration file: "MyApp.app/Contents/Resources/qt.conf" 
This file sets the plugin search path to "MyApp.app/Contents/plugins" 

当我启动时,它仍然崩溃,与以前一样。我的两个库“libQt.Shared.1.dylib”和“libQt.Framework.1.dylib”没有被调用,但两者都有这些名称的符号链接。这可能与崩溃有关吗?或者它是否会破坏链接并将其复制到其中?这两个库是我自己完成的库,他们都使用QtCore和QtNetwork。有了otool,应用程序似乎正在寻找正确的东西:

@executable_path/../Frameworks/qjson.framework/Versions/0/qjson (compatibility version 0.7.0, current version 0.7.1)
@executable_path/../Frameworks/libboost_date_time.dylib (compatibility version 0.0.0, current version 0.0.0)
@executable_path/../Frameworks/libQt.Shared.1.dylib (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/libQt.Framework.My.1.dylib (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.1)
@executable_path/../Frameworks/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.1)
@executable_path/../Frameworks/QtNetwork.framework/Versions/4/QtNetwork (compatibility version 4.8.0, current version 4.8.1)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)

请帮帮我......

3 个答案:

答案 0 :(得分:4)

我在打包PyQt应用程序之前也看到了这一点。修复(通常由macdeployqt完成)是将qt.conf文件放在应用程序的Contents/Resources目录中。它通常只包含插件目录的名称:

内容/资源/ qt.conf

[Paths]
Plugins = plugins

这将使其停止尝试查看您的系统以查找Qt库。您不应该需要-dmg标志,因为这与此情况无关。我建议只在干净的构建上运行macdeployqt MyApp.app,看看它是否为你创建了qt.conf。

答案 1 :(得分:2)

我解决了错误“将使用其中一个。未定义哪一个。”通过以下方式:由于Qt框架已安装到/Library/Frameworks,因此dyld在运行应用程序时也会看到它。我重命名了所有与Qt相关的框架(包括那些不以“Qt”开头的框架,如phonon!)因此无法找到它们。然后我再次从Xcode运行我的应用程序,这让我发现实际上我没有包含所有依赖项。例如,声子本身需要QtDBus和QtXml。由于我忘了将它们添加到我的项目中,所以dyld会使用例如全局/Library/Frameworks/QtXml.framework,而后者依赖于QtCore。但是QtCore也从全局目录加载,这可能导致各种错误。在我的例子中,应用程序无限期地挂在QWebpage构造函数中。其他人似乎经历过崩溃。解决方案当然是在您自己的应用程序中包含并修补所有必需的Qt组件(通过install_name_tool)。

更新:在我将全局名称重命名为原始名称之后,我仍然遇到问题,因为这两个地方都被考虑了。仍在努力解决这个问题。我将这里留下上述答案仅供记录。

答案 2 :(得分:0)

我发现了这个问题,如果有问题,我会在这里发布我的答案。

我完全忘记了我的lib,我正在加载运行时没有使用本地框架构建的运行时。当我删除插件时它运行正常,现在一切都很好:)