windows 最小的 Qt 可执行文件大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/450455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:49:46  来源:igfitidea点击:

Minimal Qt executable-size

c++windowsqt

提问by Christof Schardt

Now that Qt goes LGPL I tend to give it a try again. Years ago I decided against for some reasons, one of them being the huge size of executables (Qt on windows). I found a lower limit of about 5MB. Trolltech affirmed this on request but told me, that the granularity will be improved, which would lead to smaller sizes (depending on required elements).

现在 Qt 转为 LGPL,我倾向于再试一次。几年前,我出于某些原因决定反对,其中之一是巨大的可执行文件(Windows 上的 Qt)。我发现下限约为 5MB。奇趣科技应要求确认了这一点,但告诉我,粒度将得到改善,这将导致更小的尺寸(取决于所需的元素)。

Things could have changed meanwhile. Which is the size of "hello world" (windows and console) in Qt nowadays?

与此同时,事情可能会发生变化。现在 Qt 中“hello world”(窗口和控制台)的大小是多少?

It's about statically linking. I think qtCore and qtGui are required.

它是关于静态链接的。我认为 qtCore 和 qtGui 是必需的。

回答by schnaader

There is a Discussion from 2007here, the smallest number I saw there after a quick glance over it was 1.3 MB (compressed using UPX), so it seems it can be lowered a bit, but still is fairly large.

这里有一个2007 年讨论,我快速浏览后看到的最小数字是 1.3 MB(使用UPX压缩),所以它似乎可以降低一点,但仍然相当大。

回答by Daniel Lopez

Our Installbuilder for Qtproduct is a crossplatform installation tools that has a Qt frontend and is used by many commercial developers (including Trolltech itself for packaging their QtCreator IDE). Using 4.4 and compiling out the parts that we did not need, we got the overhead down to 4.1 Mb on Linux x86, 5.2M on Linux x64 and 5.3Mb on Windows. Take into account that this is before processing it with UPX. Also, if the same binary needs to support multiple Linux distributions, you may need to consider shipping libstdc++, which will add about 800kb to the size.

我们的Installbuilder for Qt产品是一个平台的安装工具,它有一个 Qt 前端,被许多商业开发人员使用(包括 Trolltech 本身用于打包他们的QtCreator IDE)。使用 4.4 并编译出我们不需要的部分,我们将开销降低到 Linux x86 上的 4.1 Mb、Linux x64 上的 5.2M 和 Windows 上的 5.3Mb。考虑到这是在使用 UPX 处理之前。此外,如果同一个二进制文件需要支持多个 Linux 发行版,您可能需要考虑发布 libstdc++,这将增加大约 800kb 的大小。

You will need to build your own versions, and basically enable / disable ifdef# for widgets that you do not use, image formats you do not need to support, etc. Although the Qt source code is already prepared for that, and there are some tools that should help, the reality is that it is a cumbersome manual process (but necessary for an app like ours). Their embedded version (formerly known as QTopia) and 'regular' Qt were merged into the same codebase, so I am sure moving forward it will be increasingly easier to build customized/trim down versions.

您将需要构建自己的版本,并且基本上为您不使用的小部件、您不需要支持的图像格式等启用/禁用 ifdef#。尽管 Qt 源代码已经为此准备好了,并且有一些应该有帮助的工具,但实际上这是一个繁琐的手动过程(但对于我们这样的应用程序来说是必需的)。他们的嵌入式版本(以前称为 QTopia)和“常规”Qt 被合并到同一个代码库中,所以我确信向前发展它会越来越容易构建定制/修剪版本。

回答by Henrik Hartz

This depends largely on your configuration and deployment method. You can of course compile as static which will exclude code which isn't used. You can also strip out things like exceptions and STL which will make memory and disk footprint even smaller. And finally, whether you are using a compressed file system like squashfs, cramf or jffs2. Try

这在很大程度上取决于您的配置和部署方法。您当然可以编译为静态,这将排除未使用的代码。您还可以去除异常和 STL 之类的东西,这将使内存和磁盘占用空间更小。最后,无论您使用的是像 squashfs、cramf 还是 jffs2 这样的压缩文件系统。尝试

configure --help

for lots of options. With the embedded ports of Qt for Embedded Linux and Windows CE you can also use qconfig to load configuration files which allow you to strip out many feature groups. See http://doc.trolltech.com/main-snapshot/fine-tuning-features.htmlfor more info.

有很多选择。使用 Qt for Embedded Linux 和 Windows CE 的嵌入式端口,您还可以使用 qconfig 加载配置文件,这允许您剥离许多功能组。有关更多信息,请参阅http://doc.trolltech.com/main-snapshot/fine-tuning-features.html