問題描述
我是 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 嗎?
希望有所幫助.
這篇關于我是否必須在我的應用程序中包含所有這些 Qt dll?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!