部署Qt框架与Mac应用程序和使用otool [英] Deploying Qt Frameworks with Mac app and usage of otool

查看:267
本文介绍了部署Qt框架与Mac应用程序和使用otool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac应用程序中部署Qt框架时遇到问题,希望有些人可以知道为什么我会在干净的Mac上运行应用程序(即不是开发者Mac)时出现此错误。



操作系统:10.7 .2并使用XCode



错误msg:

 未加载库:@loader_path /../ Frameworks / QtCore.framework / Versions / 4.0 / QtCore 
引用自:/ Users / someUser / Downloads /MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml

显然有些错误,因为QtXml是从/../Frameworks/../Frameworks引用的,不存在。



这是设置:我有一个dylib使用QtCore和QtXml(不是我的选择,但现在我需要这两个框架),dylib用于NSBundle,这是由主应用程序加载,该软件包位于资源文件夹中。 dylib被复制文件构建阶段移动到文件夹Contents / Frameworks,使用otool将install_name设置为(如 http://doc.qt.digia.com/4.3/deployment-mac.html ):

  @loader_path /../ Frameworks / QtCore.framework / Versions / 4.0 / QtCore 
@loader_path /../ Frameworks / QtXml.framework / Versions / 4 / QtXml

然后将Qt框架移动到Contents / Frameworks,并将install_name设置为:

  @executable_path /../框架/ QtCore.framework /版本/ 4.0 / QtCore 

$ b

和QtXml
@executable_path /../ Frameworks / QtXml.framework / Versions / 4 / QtXml
b @executable_path /../框架/ QtCore.framework /版本/ 4.0 / QtCore



现在,当我在开发人员mac上运行应用程序时,它清晰可见,因为Qt已安装,但当被移动到一个cl ean mac我得到错误msg,在控制台应用程序可读。
我已经尝试将executable_path更改为loader_path,但这没有起作用。
我不知道我做错了什么,或者为什么不会在谷歌上找不到任何东西,当然我可以看看错误的地方。任何想法如何解决这个问题?



这是整个错误消息:



< blockquote>

MainApp:错误域= NSCocoaErrorDomain代码= 3587捆绑
库无法加载,因为它损坏或缺少
必要的资源。

(dlopen_preflight(/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/
内容/ MacOS / Library):未加载库:

@loader_path /../ Frameworks / QtCore.framework / Versions / 4.0 / QtCore
引用自:/ Users / someUser / Downloads /
MainApp.app/Contents/Resources/Lib/Library.bundle/Contents /MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
原因:图像未找到)UserInfo = 0x107c5d5d0
{NSLocalizedFailureReason =该软件包已损坏或缺少必需的
资源,NSLocalizedRecoverySuggestion =尝试重新安装
包。
NSFilePath = / Users / someUser / Downloads / MainApp.a pp / Contents / Resources / Lib / Library.bundle / Contents / MacOS / Library,
NSDebugDescription = dlopen_preflight(/ Users / someUser
/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle /内容/ MacOS / Library):
未加载库:
@loader_path /../框架/ QtCore.framework /版本/ 4.0 / QtCore

引用:
/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
原因:图像未找到,
NSBundlePath = / Users / someUser / Downloads / MainApp.app / Contents / Resources / Lib / Library.bundle,
NSLocalizedDescription =捆绑包库无法加载,因为
它损坏或丢失必要的资源。}



解决方案

更新



如上所述,将QT编译为静态库是要走的路。随着小牛(10.9)的发布,我们也需要编码框架( http://furbo.org/2013/10/17/code-signing-and-mavericks/ )和QT4.8.5有一些问题( https://bugreports.qt-project.org/browse/QTBUG-32896 )。即使有建议的修复,我仍然有一些问题,在一台干净的机器上运行应用程序。因此,我最后将Qt5.2编译成staticlib,将它们链接到应用程序中,并对它们进行编码。



OLD



发生问题,我将Qt框架移动到应用程序在内容/框架中捆绑,并使用otool将路径设置为 @executable_path /../ Frameworks ,即将其从我的库包中移出。是的,解决方案很简单,但我仍然不知道为什么库可执行文件在使用@loader_path时找不到框架。



最好的解决方案可能是使用一个静态库,而不是将其包装在一个包...你每天学习;)


I have a problem deploying Qt frameworks with my Mac app, and I hope some will have a clue why I get this error, when I run the app on clean Mac, i.e. not a developer Mac.

OS: 10.7 .2 and using XCode

Error msg:

Library not loaded: @loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml

Clearly something is wrong since the QtXml is referenced from /../Frameworks/../Frameworks, which doesn’t exists.

This is the set up: I have a dylib that uses QtCore and QtXml (not by my choosing, but for now I need those two frameworks), the dylib is used in a NSBundle, which is loaded by the main app, the bundle is located in the resource folder. The dylib is moved by Copy Files Build Phase to the folder Contents/Frameworks and with otool the install_name is set to (as stated by http://doc.qt.digia.com/4.3/deployment-mac.html):

@loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
@loader_path/../Frameworks/QtXml.framework/Versions/4/QtXml

then the Qt frameworks are moved to Contents/Frameworks and the install_name of the is set to:

@executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore

and for the QtXml @executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml with reference to QtCore: @executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore

Now when I run the app on the developer mac it clearly works since Qt is installed, but when moved to a clean mac I get the error msg, readable in the Console app. I’ve tried to change the executable_path to loader_path, but this didn’t work. I have no idea what I’m doing wrong or why it won't for, and have not been able to find anything on Google, of course I could be looking at the wrong places. Any ideas how to fix this problem?

This is the entire error message:

MainApp: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle "Library" couldn’t be loaded because it is damaged or missing necessary resources."
(dlopen_preflight(/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/ Contents/MacOS/Library): Library not loaded:
@loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore Referenced from: /Users/ someUser /Downloads/ MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml Reason: image not found) UserInfo=0x107c5d5d0 {NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library, NSDebugDescription=dlopen_preflight(/Users/someUser /Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library): Library not loaded: @loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from: /Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml Reason: image not found, NSBundlePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle, NSLocalizedDescription=The bundle "Library" couldn’t be loaded because it is damaged or missing necessary resources.}

解决方案

UPDATE

As stated compiling QT to static libs is the way to go. With the release of Mavericks (10.9) we need to codesign frameworks as well (http://furbo.org/2013/10/17/code-signing-and-mavericks/), and with QT4.8.5 there are some issues (https://bugreports.qt-project.org/browse/QTBUG-32896). Even with suggested fixes I still had some issues when running the app on a clean machine. Therefore, I ended up with compiling Qt5.2 to staticlibs, link them in the app, and codesign them.

OLD

Problem sovled, I moved the Qt-frameworks into the app bundle in Contents/Frameworks and with otool set the path to @executable_path/../Frameworks, i.e. moved it out of my library bundle. Yes the solution is simple, but I'm still not sure why the library executable couldn't find the frameworks when using @loader_path.

The best solution would probably be to use a static library and not wrap it in a bundle...you learn everyday ;)

这篇关于部署Qt框架与Mac应用程序和使用otool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆