Qt windeployqt 打包的Qt动态库介绍

前言

在 Windows 平台,通常使用 Qt 的工具 windeployqt 将可执行文件的相关 Qt 依赖项部署到当前路径下。

Windows windeployqt 部署工具

Windows 部署工具 windeployqt 旨在自动化创建一个可部署文件夹的过程,该文件夹包含运行应用程序所需的 Qt 相关依赖项(库、QML 导入、插件和翻译)。它为 Windows 桌面应用程序创建了一个安装树,可以轻松地捆绑到安装包中。

该工具可以在 QTDIR/bin/windeployqt 中找到。为了正确运行,它需要在构建环境中运行。当使用 Qt 在线安装器时,应使用脚本 QTDIR/bin/qtenv2.bat 来设置它。

对于 Windows 桌面应用程序,默认情况下,编译器所需的运行时文件也会复制到部署文件夹中(除非指定了 --no-compiler-runtime 选项)。在 Microsoft Visual C++使用的发布版本中,这些包括 Visual C++可再发行包,这些包旨在由应用程序的安装程序在目标机器上递归安装。否则,将使用编译器运行时的共享库。

windeployqt 工具帮助说明:

Usage: windeployqt [options] [files]
Qt Deploy Tool 6.0.0

The simplest way to use windeployqt is to add the bin directory of your Qt
installation (e.g. <QT_DIR\bin>) to the PATH variable and then run:
  windeployqt <path-to-app-binary>
If ICU, etc. are not in the bin directory, they need to be in the PATH
variable. If your application uses Qt Quick, run:
  windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>

Options:
  -?, -h, --help              Displays help on commandline options.
  --help-all                  Displays help including Qt specific options.
  -v, --version               Displays version information.
  --dir <directory>           Use directory instead of binary directory.
  --qmake <path>              Use specified qmake instead of qmake from PATH.
  --libdir <path>             Copy libraries to path.
  --plugindir <path>          Copy plugins to path.
  --debug                     Assume debug binaries.
  --release                   Assume release binaries.
  --pdb                       Deploy .pdb files (MSVC).
  --force                     Force updating files.
  --dry-run                   Simulation mode. Behave normally, but do not
                              copy/update any files.
  --no-patchqt                Do not patch the Qt6Core library.
  --ignore-library-errors     Ignore errors when libraries cannot be found.
  --no-plugins                Skip plugin deployment.
  --no-libraries              Skip library deployment.
  --qmldir <directory>        Scan for QML-imports starting from directory.
  --qmlimport <directory>     Add the given path to the QML module search
                              locations.
  --no-quick-import           Skip deployment of Qt Quick imports.
  --translations <languages>  A comma-separated list of languages to deploy
                              (de,fi).
  --no-translations           Skip deployment of translations.
  --no-system-d3d-compiler    Skip deployment of the system D3D compiler.
  --compiler-runtime          Deploy compiler runtime (Desktop only).
  --no-virtualkeyboard        Disable deployment of the Virtual Keyboard.
  --no-compiler-runtime       Do not deploy compiler runtime (Desktop only).
  --json                      Print to stdout in JSON format.
  --no-opengl-sw              Do not deploy the software rasterizer library.
  --list <option>             Print only the names of the files copied.
                              Available options:
                               source:   absolute path of the source files
                               target:   absolute path of the target files
                               relative: paths of the target files, relative
                                         to the target directory
                               mapping:  outputs the source and the relative
                                         target, suitable for use within an
                                         Appx mapping file
  --verbose <level>           Verbose level (0-2).

Qt libraries can be added by passing their name (-xml) or removed by passing
the name prepended by --no- (--no-xml). Available libraries:
bluetooth concurrent core declarative designer designercomponents gui qthelp
multimedia multimediawidgets multimediaquick network nfc opengl openglwidgets
positioning printsupport qml qmltooling quick quickparticles quickwidgets script
scripttools sensors serialport sql svg svgwidgets test websockets widgets xml
webenginecore webengine webenginewidgets 3dcore 3drenderer 3dquick
3dquickrenderer 3dinput 3danimation 3dextras geoservices webchannel serialbus
webview

Arguments:
  [files]                     Binaries or directory containing the binary.

例如使用 windeployqt 工具后, Qt 6.7.0 的动态库依赖如下:

.
├── Qt6Cored.dll
├── Qt6Guid.dll
├── Qt6Networkd.dll
├── Qt6Svgd.dll
├── Qt6Widgetsd.dll
├── QtProjectTemplate.exe
├── concrt140d.dll
├── d3dcompiler_47.dll
├── dxcompiler.dll
├── dxil.dll
├── generic
│   └── qtuiotouchplugind.dll
├── iconengines
│   └── qsvgicond.dll
├── imageformats
│   ├── qgifd.dll
│   ├── qicod.dll
│   ├── qjpegd.dll
│   └── qsvgd.dll
├── msvcp140_1d.dll
├── msvcp140_2d.dll
├── msvcp140d.dll
├── msvcp140d_atomic_wait.dll
├── msvcp140d_codecvt_ids.dll
├── networkinformation
│   └── qnetworklistmanagerd.dll
├── opengl32sw.dll
├── platforms
│   └── qwindowsd.dll
├── styles
│   └── qmodernwindowsstyled.dll
├── tls
│   ├── qcertonlybackendd.dll
│   ├── qopensslbackendd.dll
│   └── qschannelbackendd.dll
├── translations
│   ├── qt_ar.qm
│   ├── ...
│   ├── qt_zh_CN.qm
│   └── qt_zh_TW.qm
├── vccorlib140d.dll
├── vcruntime140_1d.dll
├── vcruntime140_threadsd.dll
└── vcruntime140d.dll

Qt 5.15.2 动态库依赖如下:

.
├── D3Dcompiler_47.dll
├── QtProjectTemplate.exe
├── Qt5Cored.dll
├── Qt5Guid.dll
├── Qt5Svgd.dll
├── Qt5Widgetsd.dll
├── iconengines
│   └── qsvgicond.dll
├── imageformats
│   ├── qgifd.dll
│   ├── qicnsd.dll
│   ├── qicod.dll
│   ├── qjpegd.dll
│   ├── qsvgd.dll
│   ├── qtgad.dll
│   ├── qtiffd.dll
│   ├── qwbmpd.dll
│   └── qwebpd.dll
├── libEGLd.dll
├── libGLESv2d.dll
├── opengl32sw.dll
├── platforms
│   └── qwindowsd.dll
├── styles
│   └── qwindowsvistastyled.dll
└── translations
    ├── qt_ar.qm
    ├── ...
    └── qt_zh_TW.qm

依赖动态库介绍

分发运行 Qt 应用程序所需的所有 Qt DLL 和应用程序特定插件的存档必须包括以下文件:

组件文件名
可执行文件qt-demo.exe
Qt Windows 平台插件platforms\qwindows.dll
Qt Windows Vista 风格的插件styles\qwindowsvistastyle.dll
Qt 核心模块Qt6Core.dll
Qt GUI 模块Qt6Gui.dll
Qt Widgets 模块Qt6Widgets.dll

根据应用程序使用的功能,可能需要其他插件 (iconengines, imageformats)。

iconengines:

  • qsvgicon.dll:SVG 图标支持

imageformats

  • qgif.dll:提供对 GIF 图像格式的支持。
  • qicns.dll:提供对 ICNS 图像格式的支持。
  • qico.dll:提供对 ICO 图像格式的支持。
  • qjpeg.dll:提供对 JPEG 图像格式的支持。
  • qsvg.dll:提供对 SVG 图像格式的支持。
  • qtga.dll:提供对 TGA 图像格式的支持。
  • qtiff.dll:提供对 TIFF 图像格式的支持。
  • qwbmp.dll:提供对 WBMP 图像格式的支持。
  • qwebp.dll:提供对 WebP 图像格式的支持。

注意:以上imageformats列举的动态库为 Qt 5,在 Qt 6 中有所变化,缩减了一些动态库。

此外,如果采用的是 MSVC 编译器,存档必须包含以下编译器特定的库(假设为 Visual Studio 2019):

组件文件名
C 运行时vcruntime140.dll
C++ 运行时msvcp160.dll

如果使用了动态 OpenGL,则档案可能还包含:

组件文件名
OpenGL 软件渲染库opengl32sw. dll

而在Qt 5中,如果使用动态 OpenGL,还需要包含 ANGLE 和软件渲染所需的库:

组件文件名
OpenGL 软件渲染库opengl32sw. dll
ANGLE 库libEGL.dll, libGLESv2.dll
ANGLE 的 HLSL 编译器库d3dcompiler_XX.dll

如果 Qt 配置为使用 ICU,则归档文件必须包含:

ICU 组件文件名
icudtXX. dll
icuinXX. dll
icuucXX. dll

与非系统库的直接依赖关系:

QtVisual Studio 16 (2019)MinGW
Qt6Core.dll
Qt6Gui.dll
Qt6Widgets.dll
vccorlib140.dll
vcruntime140d.dll
msvcp140.dll
libwinpthread-1.dll
libgcc_s_seh-1.dll
libstdc+±6.dll

Qt 6 中增加了传输层安全性(TLS)相关的插件,即tls目录:

  • qcertonlybackend.dll:提供了一个仅用于证书处理的后端实现。它可以用于验证证书链、检查证书的有效性和处理证书相关的任务,而不实际执行加密通信。这个后端可能在不需要完整 TLS 功能的环境中使用,比如在某些测试或调试场景中。
  • qopensslbackend.dll:基于 OpenSSL 的 TLS 后端实现。OpenSSL 是一个广泛使用的开源库,提供了丰富的加密功能和协议支持,包括 SSL 和 TLS。通过使用这个后端,Qt 应用程序可以利用 OpenSSL 的功能来实现安全的网络通信。
  • qschannelbackend.dll:提供了基于 Windows 的 SChannel(Secure Channel)安全协议的 TLS 后端实现。SChannel 是 Windows 操作系统的一部分,提供了 SSL 和 TLS 协议的支持。使用这个后端,Qt 应用程序可以在 Windows 平台上利用系统自带的安全功能来实现加密通信。

Qt 插件

所有 Qt GUI 应用程序都需要一个实现 Qt 平台抽象(QPA)层的插件。对于 Windows,平台插件的名称是 qwindows.dll。此文件必须位于您的分发目录下的特定子目录(默认为 platforms)中。或者,可以调整 Qt 用于查找其插件的搜索路径。

应用程序还可能依赖于一个或多个 Qt 插件,例如打印支持插件、JPEG 图像格式插件或 SQL 驱动程序插件。确保与您的应用程序一起分发所需的任何 Qt 插件。与平台插件类似,每种类型的插件都必须位于分发目录内特定的子目录(例如 printsupport、imageformats 或 sqldrivers)中。

总结

Qt 6 的依赖库相比 Qt5 多了很多新东西,但大多可望文生义,可猜个大概意思。也可查询官方文档进行佐证。

Qt for Windows - Deployment | Qt 6.7

  • 12
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 要将Qt项目打包动态库,可以按照以下步骤进行操作。首先,进入存放需要打包的exe文件的目录,可以使用命令行(cmd)进入该目录。然后,使用windeployqt命令,后面跟上需要打包的exe文件的名称,即可获取所需要的动态库。如果提示“不是内部或外部命令,也不是可运行的程序或批处理文件。”,可以将windeployqt所在的目录加入到环境变量中。需要注意的是,如果使用的是vs+qt生成的文件,在使用上述命令之前,建议使用vs自带的命令行,否则可能会出现缺少vc依赖的情况。具体的解决办法可以参考相关链接\[1\]。 另外,如果需要调用该动态库的程序,可以按照以下步骤进行操作。在使用该库的程序中,新建一个include文件夹和一个lib文件夹。将导出类的头文件复制到include文件夹中,将编译生成的.lib文件复制到lib文件夹中。然后,在程序中引入该头文件即可。在Qt项目中,可以在.pro文件中添加INCLUDEPATH和LIBS的配置,将include文件夹和lib文件夹添加到相应的路径中,以及链接对应的库文件\[3\]。 参考资料: \[1\] 获取需要的动态库: https://blog.csdn.net/no_say_you_know/article/details/126360830 \[2\] native-lib.cpp文件内容 \[3\] 调用动态库的步骤 #### 引用[.reference_title] - *1* [打包Qt程序(获取需要的动态库)](https://blog.csdn.net/qq_39618959/article/details/129536248)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [13、使用Android Studio开发工具,将一个QT含有第三方库的工程打包成一个动态so供Android Studio开发人员...](https://blog.csdn.net/sxj731533730/article/details/123154604)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [【QTQt 给已经开发好的程序快速封装成动态库](https://blog.csdn.net/Cappuccino_jay/article/details/126137458)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值