【Qt】自动查找Qt应用程序缺少的依赖库
- 1、背景
- 2、实例
- 3、验证
1、背景
操作系统:windows10专业版,如下图:
Qt版本:qt-opensource-windows-x86-msvc2013_64-5.7.1.exe
使用Qt安装后的qtcreator5.7.1开发Qt应用程序。
将编译生成的exe可执行程序拷贝到另外的电脑上运行出现缺少动态库的错误。
这是由于该电脑上未安装Qt软件,而你的exe程序包的文件夹又未包含依赖的动态库。
博主的Qt安装目录:E:\E01_cppIDE\E01_qt\install
如下图:
并将安装后的bin目录:E:\E01_cppIDE\E01_qt\install\Qt5.7.1\5.7\msvc2013_64\bin
添加至系统环境变量,如下图:
本博客,以实例的方式讲解如何配置Qt应用程序的依赖库。
2、实例
使用qtcreator编译生成的exe在windows虚拟机上运行报缺少依赖库,
示例如下:
解决办法:
步骤1:CMD进入可执行exe文件的目录,如下图:
步骤2:输入windeployqt xxx.exe指令。如:
windeployqt Demo_Timer.exe
运行日志如下:
C:\Users\Administrator\Desktop\Qt_App>windeployqt Demo_Timer.exe
C:\Users\Administrator\Desktop\Qt_App\Demo_Timer.exe 64 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Skipping plugin qtvirtualkeyboardplugin.dll due to disabled dependencies.
Direct dependencies: Qt5Core Qt5Widgets
All dependencies : Qt5Core Qt5Gui Qt5Widgets
To be deployed : Qt5Core Qt5Gui Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not set.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Updating libGLESV2.dll.
Updating libEGL.dll.
Updating D3Dcompiler_47.dll.
Updating opengl32sw.dll.
Patching Qt5Core.dll...
Creating directory C:/Users/Administrator/Desktop/Qt_App/iconengines.
Updating qsvgicon.dll.
Creating directory C:/Users/Administrator/Desktop/Qt_App/imageformats.
Updating qdds.dll.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjpeg.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory C:/Users/Administrator/Desktop/Qt_App/platforms.
Updating qwindows.dll.
Creating C:\Users\Administrator\Desktop\Qt_App\translations...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...
C:\Users\Administrator\Desktop\Qt_App>
3、验证
以上步骤运行结束,将自动查找依赖库,
并在可执行程序所在目录进行创建依赖项,如下图:
再次运行可执行程序,如下: