使用 Mac OS X 应用程序部署 Qt - 如何不加载任何插件?

Posted

技术标签:

【中文标题】使用 Mac OS X 应用程序部署 Qt - 如何不加载任何插件?【英文标题】:Deploying Qt with Mac OS X app - how not to load any plugins? 【发布时间】:2013-04-12 11:16:02 【问题描述】:

我想将 Qt 4.x 共享库与我的应用程序一起打包,这样用户就不必安装 Qt 框架。使用构建脚本,我正确修补了所有 Qt 依赖项,并确保不再从 /Library/Frameworks 中的 Qt 安装中加载任何依赖项(请参阅我的答案 here)。

但是现在我遇到了问题,因为在初始化期间的某个时刻,插件/Developer/Applications/Qt/plugins/bearer/libqcorewlanbearer.dylib 被加载:

$ export DYLD_PRINT_LIBRARIES=1
$ cd /path/to/my.app/Contents/MacOS
$ ./myappexecutable

dyld: loaded: /path/to/executable
dyld: loaded: /usr/lib/libz.1.dylib
dyld: loaded: /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia
dyld: loaded: /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox
dyld: loaded: /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation
dyld: loaded: /usr/lib/libxml2.2.dylib
dyld: loaded: /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
dyld: loaded: /usr/lib/libssl.0.9.8.dylib
dyld: loaded: /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit
dyld: loaded: /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo
dyld: loaded: /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtCore.framework/Versions/4/QtCore
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtGui.framework/Versions/4/QtGui
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtOpenGL.framework/Versions/4/QtOpenGL
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtWebKit.framework/Versions/4/QtWebKit
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/phonon.framework/Versions/4/phonon
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtNetwork.framework/Versions/4/QtNetwork
dyld: loaded: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
dyld: loaded: /usr/lib/libobjc.A.dylib
dyld: loaded: /usr/lib/libstdc++.6.dylib
dyld: loaded: /usr/lib/libSystem.B.dylib
dyld: loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
dyld: loaded: /usr/lib/system/libcache.dylib
[...]
dyld: loaded: /usr/lib/libsasl2.2.dylib
dyld: loaded: /System/Library/Frameworks/AGL.framework/Versions/A/AGL
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtDBus.framework/Versions/4/QtDBus
dyld: loaded: /path/to/my.app/Contents/MacOS/./../Qt/QtXml.framework/Versions/4/QtXml
dyld: loaded: /System/Library/PrivateFrameworks/CoreServicesInternal.framework/Versions/A/CoreServicesInternal
dyld: loaded: /System/Library/Frameworks/Security.framework/PlugIns/csparser.bundle/Contents/MacOS/csparser
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ColorSync.framework/Versions/A/Resources/ColorSyncDeprecated.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/libCSync.A.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/libRIP.A.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/libCGXType.A.dylib
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Resources/GLEngine.bundle/GLEngine
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLProgrammability.dylib
dyld: loaded: /System/Library/Extensions/ATIRadeonX3000GLDriver.bundle/Contents/MacOS/ATIRadeonX3000GLDriver
dyld: loaded: /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupport.dylib
dyld: loaded: /System/Library/Extensions/AppleIntelHD3000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD3000GraphicsGLDriver
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Resources//GLRendererFloat.bundle/GLRendererFloat
dyld: loaded: /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libcldcpuengine.dylib
dyld: loaded: /System/Library/PrivateFrameworks/DiskImages.framework/Versions/A/DiskImages
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCoreFSCache.dylib
dyld: loaded: /System/Library/Frameworks/DiscRecording.framework/Versions/A/DiscRecording
dyld: loaded: /usr/lib/libcurl.4.dylib
dyld: loaded: /System/Library/PrivateFrameworks/MediaKit.framework/Versions/A/MediaKit
dyld: loaded: /Developer/Applications/Qt/plugins/bearer/libqcorewlanbearer.dylib
[^^^ this one is problematic as it loads global Qt libraries, see below]
dyld: loaded: /System/Library/Frameworks/CoreWLAN.framework/Versions/A/CoreWLAN
dyld: loaded: /Library/Frameworks/QtNetwork.framework/Versions/4/QtNetwork
dyld: loaded: /Library/Frameworks/QtCore.framework/Versions/4/QtCore
QObject::moveToThread: Current thread (0x7fc2d260b280) is not the object's thread (0x7fc2d4245fd0).
Cannot move to target thread (0x7fc2d260b280)

该插件引用了全局安装的 Qt 框架,然后我实际上加载了两组 Qt 二进制文件,导致各种麻烦。

现在我的问题是:该插件在哪里加载(找不到任何包含“wlanbearer”的二进制文件)以及如何确保没有插件从我的应用程序中自动加载?

【问题讨论】:

你还有这个问题吗?通常,如果您使用 macdeployqt 修复依赖项,Qt 库加载的插件也会被复制。 很好,看起来正是我现在所看到的 :) 如果你当时解决了它,你还记得吗? 我包含了该插件,因为我不知道如何禁用加载它。 【参考方案1】:

尝试在 QApplication 初始化后立即替换插件路径:

QApplication app(argc, argv);
QCoreApplication::removeLibraryPath(QLibraryInfo::location(QLibraryInfo::PluginsPath));
QCoreApplication::addLibraryPath("../../PlugIns");

它对我有用。

【讨论】:

这并没有避免加载插件,只是用代码替换了qt.conf文件。 在我的情况下,插件由 macdeployqt 捆绑,但首先加载 Qt 安装中的外部插件。 qt.conf 文件包含包中插件目录的正确路径。

以上是关于使用 Mac OS X 应用程序部署 Qt - 如何不加载任何插件?的主要内容,如果未能解决你的问题,请参考以下文章

Mac Os X 中类似 Windows 的 Qt4 菜单栏

Qt Mac OS 应用程序部署缺少框架

Qt Mac OS 部署 - 您必须提供 Apple ID

Qt for mac os - 将项目部署到应用程序文件

如何用mac os x server搭建网站?

在 Mac Os X 上使用 CGEvent 和 Qt