問(wèn)題描述
我是 Qt 的新手,我不知道很多東西.
I'm totally new in using Qt and I don't know a lot of stuff.
作為測(cè)試,我使用 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
我編譯應(yīng)用程序后它對(duì)我不起作用(給出錯(cuò)誤),我在互聯(lián)網(wǎng)上搜索,發(fā)現(xiàn)很多人說(shuō)我必須從目錄中復(fù)制下面提到的那些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
我必須復(fù)制 DLL 才能使我的應(yīng)用程序正常工作:
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
我的問(wèn)題是這些 dll 的大小,它們大約為37 MB",而我的應(yīng)用程序本身只有30 KB"!因此,這些 Qt 庫(kù)將至少為我的應(yīng)用程序增加 37 MB [我沒(méi)有看到我下載的其他基于 Qt 的應(yīng)用程序會(huì)發(fā)生這種情況].有什么解決方案可以讓我最終得到一個(gè)小的 .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?!
而且我聽(tīng)到有人說(shuō)我還必須為 Microsoft C++ Compiler 包含一個(gè) 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 上遇到了很多問(wèn)題,但我找不到任何可以幫助我的問(wèn)題,所以請(qǐng)不要將其標(biāo)記為重復(fù),因?yàn)槿绻艺业搅嗣鞔_的回答我不會(huì)發(fā)布這個(gè)問(wèn)題!
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最簡(jiǎn)單的方法就是在bin目錄下添加您的 Qt 安裝(例如)到 PATH 變量,然后運(yùn)行:
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>
更新:經(jīng)過(guò)進(jìn)一步測(cè)試,windeployqt
沒(méi)有為我復(fù)制所有的 MingW dll.(在 Windows 10 和 MingW 4.9.1 上用 Qt 5.4 測(cè)試).所以需要在部署前手動(dòng)獲取最后3個(gè)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
來(lái)自
C:Qt5.4mingw491_32in
<小時(shí)>
我想你的列表中可能有一些額外的東西......我會(huì)仔細(xì)檢查下面鏈接中的文檔......
I think you may have a few extras in your list... I would double check the docs in the links below...
這是關(guān)于它的權(quán)威文檔:
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 庫(kù)可以做很多事情,但它們有點(diǎn)大.一些舊版本的 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.
對(duì)于 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 在運(yùn)行時(shí)跟蹤庫(kù)的方式:
Here is how Windows tracks down a library at runtime:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx
如果您靜態(tài)鏈接,那么您的 EXE 應(yīng)該獲取它需要的庫(kù)并構(gòu)建到一個(gè)獨(dú)立的 exe 中.它仍然可能依賴(lài)于 msvc 可再發(fā)行組件.有關(guān)更多信息,請(qǐng)參閱下一節(jié).但它現(xiàn)在將您引用到 EXE 的 .lib
編譯下來(lái),并且您的 exe 不再指向其他動(dòng)態(tài)鏈接庫(kù).設(shè)置靜態(tài)鏈接的 exe 環(huán)境確實(shí)需要更多時(shí)間.
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 肯定會(huì)變得更大,因?yàn)樗F(xiàn)在包含您之前引用的庫(kù)的二進(jìn)制信息.
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+靜態(tài)+鏈接
靜態(tài)構(gòu)建 exe,意味著您沒(méi)有使用 LGPL 版本.這意味著如果您使用 LGPL,您必須讓最終用戶(hù)易于訪問(wèn)您的目標(biāo)文件.
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.
我認(rèn)為@peppe 描述得很好(見(jiàn)下面的評(píng)論):
I think @peppe described it well (see comment below):
從技術(shù)上講,在 LGPL 下使用 Qt 時(shí)允許靜態(tài)鏈接,即使您的應(yīng)用程序未使用 LGPL.唯一棘手的要求是讓第三方能夠?qū)⒛膽?yīng)用程序重新鏈接到不同的 Qt 版本.但是你可以很容易地遵守,f.i.通過(guò)為您的應(yīng)用程序提供一個(gè)巨大的目標(biāo)文件 (.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/
查看底部附近的圖表.如果你做的是商業(yè)版,那么你可以靜態(tài)鏈接,不用擔(dān)心目標(biāo)文件.
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.
可再發(fā)行依賴(lài)項(xiàng)與運(yùn)行時(shí)庫(kù)鏈接器選項(xiàng)有關(guān).
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
(使用運(yùn)行庫(kù))
要在開(kāi)發(fā)環(huán)境中找到這些選項(xiàng),請(qǐng)單擊項(xiàng)目"菜單上的設(shè)置".然后單擊 C/C++ 選項(xiàng)卡,然后單擊類(lèi)別框中的代碼生成.請(qǐng)參閱使用運(yùn)行時(shí)庫(kù)下拉框.
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.
下面這兩個(gè)鏈接討論了一些舊版本的visual studio,但推理應(yīng)該仍然成立.
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 制作一個(gè)完全靜態(tài)鏈接的 .exe 嗎?
希望有所幫助.
這篇關(guān)于我是否必須在我的應(yīng)用程序中包含所有這些 Qt dll?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!