我是否必须在我的应用程序中包含所有这些 Qt dll?
我是 Qt 的新手,我不知道很多东西.
I'm totally new in using Qt and I don't know a lot of stuff.
作为测试,我使用 Visual Studio 2012 和基于最新 Qt5.1
As a test I created a simple application using Visual Studio 2012 and Qt-VS-Add-in based on the newest Qt5.1
我编译应用程序后它对我不起作用(给出错误),我在互联网上搜索,发现很多人说我必须从目录中复制下面提到的那些dll:
After I compiled the application it didn't work for me (gave errors), I searched all over the internet and found a lot of people saying that I have to copy those dlls mentioned below from the directory:
C:QtQt5.1.05.1.0msvc2012in
我必须复制 DLL 才能使我的应用程序正常工作:
DLL's I had to copy to make my application work:
icudt51.dll
icuin51.dll
icuuc51.dll
libEGL.dll
libGLESv2.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
我的问题是这些 dll 的大小,它们大约为37 MB",而我的应用程序本身只有30 KB"!因此,这些 Qt 库将至少为我的应用程序增加 37 MB [我没有看到我下载的其他基于 Qt 的应用程序会发生这种情况].有什么解决方案可以让我最终得到一个小的 .exe 文件吗?!
My problem is the size of these dlls, they're about "37 MB" and my application itself is only "30 KB"! So, those Qt libraries will add at least 37 MB to my application [ Which I don't see it happens with other Qt-based applications I download ]. Is there any solution can make me end up with a single small .exe file?!
而且我听到有人说我还必须为 Microsoft C++ Compiler 包含一个 dll,您能为我解释一下吗?
And I heard some people saying that I have to also include a dll for Microsoft C++ Compiler, can you explain this for me?
注意:我在 StackOverFlow 上遇到了很多问题,但我找不到任何可以帮助我的问题,所以请不要将其标记为重复,因为如果我找到了明确的回答我不会发布这个问题!
Note: I've come across a lot of questions here on StackOverFlow but I couldn't find anything can help me, so please do not flag this as a duplication because if I found a clear answer I wouldn't post this question!
任何帮助将不胜感激.
推荐答案
更新:使用windeployqt.exe
!效果非常好.
UPDATE: Use windeployqt.exe
! It works really well.
http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool
使用windeployqt最简单的方法就是在bin目录下添加您的 Qt 安装(例如)到 PATH 变量,然后运行:
The simplest way to use windeployqt is to add the bin directory of your Qt installation (e.g. ) to the PATH variable and then run:
windeployqt <path-to-app-binary>
更新:经过进一步测试,windeployqt
没有为我复制所有的 MingW dll.(在 Windows 10 和 MingW 4.9.1 上用 Qt 5.4 测试).所以需要在部署前手动获取最后3个dll:
UPDATE: Upon Further testing, windeployqt
did not copy over all the MingW dlls for me. (Tested with Qt 5.4 on Windows 10 with MingW 4.9.1). So you need to manually get the last 3 dlls before deploying:
libgcc_s_dw2-1.dll
libstdc++-6.dll
libwinpthread-1.dll
来自
C:Qt5.4mingw491_32in
<小时>
我想你的列表中可能有一些额外的东西......我会仔细检查下面链接中的文档......
I think you may have a few extras in your list... I would double check the docs in the links below...
这是关于它的权威文档:
Here is the definitive documentation on it:
http://doc.qt.io/qt-5/windows-部署.html
http://doc.qt.io/qt-5/windows-deployment.html#application-dependencies
令人惊叹的 Qt 库可以做很多事情,但它们有点大.一些旧版本的 Qt 可能要小一些.
The amazing Qt Libraries can do a lot, but they are kind of big. Some of the older versions of Qt might be a little smaller.
对于 Qt 4.8 msvc,QtCore4.dll
为 2.5 MB,QtGui4.dll
为 8.4 MB.
For Qt 4.8 msvc QtCore4.dll
is 2.5 MB, and QtGui4.dll
is 8.4 MB.
以下是 Windows 在运行时跟踪库的方式:
Here is how Windows tracks down a library at runtime:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx
如果您静态链接,那么您的 EXE 应该获取它需要的库并构建到一个独立的 exe 中.它仍然可能依赖于 msvc 可再发行组件.有关更多信息,请参阅下一节.但它现在将您引用到 EXE 的 .lib
编译下来,并且您的 exe 不再指向其他动态链接库.设置静态链接的 exe 环境确实需要更多时间.
If you statically link, then your EXE should grab the libraries it needs and gets built into a stand alone exe. It still may be dependent on msvc redistributables. See the next section for more info on it. But it now compiles down the .lib
s that you reference into your EXE and your exe no longer is pointing at other dynamically linked libraries. It does take more time to get your statically linked exe environment setup.
您的 exe 肯定会变得更大,因为它现在包含您之前引用的库的二进制信息.
Your exe will certainly get bigger as it now includes the binary information for the libraries that you referenced before.
https://www.google.com/search?q=qt+静态+链接
静态构建 exe,意味着您没有使用 LGPL 版本.这意味着如果您使用 LGPL,您必须让最终用户易于访问您的目标文件.
Statically building the exe, means that you aren't using the LGPL version.
means that you have to have your object files easy to access to end users if you are using LGPL.
我认为@peppe 描述得很好(见下面的评论):
I think @peppe described it well (see comment below):
从技术上讲,在 LGPL 下使用 Qt 时允许静态链接,即使您的应用程序未使用 LGPL.唯一棘手的要求是让第三方能够将您的应用程序重新链接到不同的 Qt 版本.但是你可以很容易地遵守,f.i.通过为您的应用程序提供一个巨大的目标文件 (.o),只需将其链接到任何 Qt 版本即可.
Technically, you are allowed to statically link when using Qt under LGPL, even if your application is not using LGPL. The only tricky requirement is keeping the ability for a third party to relink your application against a different Qt version. But you can comply with that easily, f.i. by providing a huge object file (.o) of your application, that only needs to be linked against any Qt version.
http://blog.qt.io/blog/2009/11/30/qt-making-the-right-licensing-decision/
查看底部附近的图表.如果你做的是商业版,那么你可以静态链接,不用担心目标文件.
Look at the chart near the bottom. If you are doing the commercial version, then you can statically link, without worrying about the object files.
可再发行依赖项与运行时库链接器选项有关.
Redistributable dependencies have to do with the run-time library linker options.
http://msdn.microsoft.com/en-us/library/aa278396(v=vs.60).aspx
/MD、/ML、/MT、/LD
(使用运行库)
要在开发环境中找到这些选项,请单击项目"菜单上的设置".然后单击 C/C++ 选项卡,然后单击类别框中的代码生成.请参阅使用运行时库下拉框.
To find these options in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click Code Generation in the Category box. See the Use Run-Time Library drop-down box.
下面这两个链接讨论了一些旧版本的visual studio,但推理应该仍然成立.
These two links below talk about some older versions of visual studio, but the reasoning should still stand.
http://www.davidlenihan.com/2008/01/choosing_the_correct_cc_runtim.html
如何使用 Visual Studio Express 2005 制作一个完全静态链接的 .exe 吗?
希望有所帮助.
相关文章