解决 Qt 应用程序大小的方法
带有网络库和 GUI 库的 Qt 应用程序大约有 10MB;也就是说,没有代码。
对于像我这样有互联网连接的人来说,这有点不方便;特别是当涉及到很少使用的程序时(即使用过一次然后就离开了)。
我尝试使用LZMA和LZMA2压缩来压缩exe文件,但它什么也没做。
我想让代码本身更小,有什么办法吗?我可以缩小多少尺寸?至少在网络库方面是这样。
PS:我不想使用UPX或此类应用程序。
A Qt app with the networking library and the GUI library gets to about 10MB; that is, without code.
For people with Internet connection like mine, that is a bit inconvenient; specially when it comes to a program that is rarely used (i.e. used once and then left.)
I tried to use LZMA and LZMA2 compressions to compress the exe files, and it did nothing.
I would like to make the code itself smaller, is there a way to do that? How much can I go down in size? At least when it comes to the networking library.
PS: I wouldn't like to use UPX or such applications.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试静态链接;这也许能够从库中丢弃未使用的代码。但请注意,这可能会影响您在 Qt 开源许可证下的义务;分发静态链接到 LGPL 许可库的闭源(通常是非 LGPL)应用程序会带来 与动态链接情况相比的额外义务。当然,如果您的应用程序本身是 GPL 或 LGPL 许可的,那么这没有问题。
You could try statically linking; this may be able to discard unused code from the library. Please note, however, that this may impact your obligations under Qt's open source licenses; distributing a closed-source (generally, non-LGPL) application statically linked against a LGPL-licensed library brings with it additional obligations when compared to the dynamic-linking case. Of course, if your application is GPL or LGPL licensed itself, this is no problem.
您可以从源代码重建 Qt,跳过不需要的部分。请参阅配置选项,了解可以省略的事项列表。例如
-no-openssl
将使网络库更小。You could rebuild Qt from source, skipping the bits that you don't need. See configure options for a list of things that you can leave out. E.g.
-no-openssl
will make the network library smaller.这是我写的一份缩小 Qt 的指南:
http ://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/
Here is a guide I wrote to making Qt smaller:
http://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/