将Qt5.5 动态链接生成的exe及依赖dll打包方法

Qt静态编译链接生成的exe文件,不需依赖七大姑八大姨的一堆dll,可以独立运行,发布很方便。但绝大多数用的都是Qt开源版本,如果用静态链接,会有些限制。那有没有办法即能享受静态编译的方便,又不受开源许可的限制呢?方法之一,就是用动态编译,然后把exe和需要的dll整合成一个文件,问题就解决了。

 

使用工具:

  1. Enigmavb(单文件封装工具)

           下载:http://pan.baidu.com/s/1slcfArj

 

  1. windeployqt(qt内置一个现成的dll依赖性工具)

位置:工具在qt安装目录的bin/目录下

 

操作步骤:

第一步:是添加qt的bin/目录进系统path变量。很简单,在系统属性里设置,添加D:\Qt\5.4\msvc2010_opengl\bin;到系统path环境变量。(qt安装目录不尽相同)

 

第二部:在任意目录新建文件夹,把编译完成后的qt exe可执行程序拷贝过去。从命令行模式进入该文件夹,执行语句windeployqt xxxx.exe. 之后该工具会分析程序依赖性,自动添加必要dll文件至该目录。运行时命令行提示如下

 

D:\TVS\Qt\LGTVSerialControl>windeployqt terminal.exe --release
D:\TVS\Qt\LGTVSerialControl\terminal.exe 32 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Direct dependencies: Qt5Core Qt5Gui Qt5SerialPort Qt5Widgets
All dependencies   : Qt5Core Qt5Gui Qt5SerialPort Qt5Widgets
To be deployed     : Qt5Core Qt5Gui Qt5SerialPort Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not s
et.
Updating icuin53.dll.
Updating icuuc53.dll.
Updating icudt53.dll.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5SerialPort.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Creating directory iconengines.
Updating qsvgicon.dll.
Creating directory imageformats.
Updating qdds.dll.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjp2.dll.
Updating qjpeg.dll.
Updating qmng.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory platforms.
Updating qwindows.dll.
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_fi.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...

D:\TVS\Qt\LGTVSerialControl>

这样必要的库文件就自动添加完毕。

 

第三步:打包

打包工具,这里选用Enigma Virtual Box,为free的软件。

下载:http://enigmaprotector.com/assets/files/enigmavb.exe安装,运行

Enter Input File Name中,选择编译完成后的qt exe可执行程序

Enter Output File Name,输出文件名称

点Add按钮,将前面准备好的dll文件,添加进来

点Files Options,勾选Enable Files Virtualization和Compress files,OK

 

 

 

最后,点Process,大告成。打包生成的exe文件也可以象静态编译的一样,可以独立运行了。

 

 

参考地址:

http://blog.csdn.net/ztz0223/article/details/8939341

http://www.bubuko.com/infodetail-725364.html

posted on 2016-04-17 18:24  OceanWang  阅读(1027)  评论(0编辑  收藏  举报

导航