简体   繁体   English

Qt:我怎样才能减轻我的体重

[英]Qt: How can I make my exe 'weight' less

I'm making a program (let's call it ProgramWP) made with Qt 4.8.5 on a Fedora and based on a QWizard structure with its QWizardPages. 我正在使用Qt 4.8.5在Fedora上创建一个程序(我们称之为ProgramWP),并基于QWizard结构及其QWizardPages。 The program has more or less 50 classes, 30 of them are QWizardPages. 该程序有或多或少50个类,其中30个是QWizardPages。

The thing is that the program executable 'weights' (dunno the english word/expression) 8Mb ( the release version) and I want to know: 问题是程序可执行'权重'(dunno英文单词/表达式)8Mb(发布版本),我想知道:

  • Why does it weight so much? 它为什么这么重? Which is the cause? 原因是什么?
  • How can I reduce it? 我怎样才能减少它?

I need to reduce it because in the product of the enterprise, there are some applications runing, some of them mine. 我需要减少它,因为在企业的产品中,有一些应用程序在运行,其中一些是我的。 To sup up the exe's: 为了支持exe:

  • ProgramMAIN (1.5MiB): the main program of the enterprise. ProgramMAIN (1.5MiB):企业的主要程序。
  • ProgramMAIN2 (600KiB): another important program of the enterprise. ProgramMAIN2 (600KiB):企业的另一个重要程序。
  • ProgramWP (8MiB): My main program (made with Qt). ProgramWP (8MiB):我的主程序(用Qt制作)。
  • ProgramMINI (2.5Mib): My mini version of my main program (made with Qt). ProgramMINI (2.5Mib):我的主程序的迷你版本(用Qt制作)。
  • Program3 (1.3MiB): My other program made with Qt Program3 (1.3MiB):我用Qt制作的另一个程序

As you can see my main program weights so so so much than the main one while the main one is soooo much bigger (ProgramWP is just a little program to configure some easy things). 正如你可以看到我的主程序权重如此大于主要程序,而主要程序是如此大得多(ProgramWP只是一个小程序来配置一些简单的事情)。

I'm linking statically some of our libs in ProgramWP and ProgramMINI but so does programMAIn and ProgramMAIN2 so... knowing that ProgramMain2 is 600Kibs with the linked libraries, my ProgramWP should not weight more than that. 我正在静态链接ProgramWP和ProgramMINI中的一些libs,但programMAIn和ProgramMAIN2也是如此......所以我知道ProgramMain2与链接库是600Kibs,我的ProgramWP不应该超过它。

This is how I do the linking in the .pro file: 这是我在.pro文件中进行链接的方式:

unix:!macx: LIBS += -L$PWD/../../ConfigLib/Release/ -lLib1
INCLUDEPATH += $PWD/../../Lib1
DEPENDPATH += $PWD/../../Libs/Release
unix:!macx: PRE_TARGETDEPS += $PWD/../../Libs/Release/Lib1.a

I've searched and asked and found that I could add the QMAKE_CXX_FLAGS+= -s line to the .pro file to delete the unnecesary symbolsand after doing it and runing the qmake, it stills weight the same (It's like if it was ignored). 我已经搜索并询问并发现我可以将QMAKE_CXX_FLAGS+= -s行添加到.pro文件中以删除不需要的符号,在执行并运行qmake之后,它仍然具有相同的权重(就像它被忽略一样)。 I've see if gcc uses the -s param and rebuilding I get: 我看到gcc是否使用-s param并重建我得到:

g++ -c -pipe -std=c++11 -s -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_SCRIPT_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib/qt4/mkspecs/linux-g++ -I../MyProject-I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include/QtXml -I/usr/include/QtScript -I/usr/include -I../../Utils -I../../Lib1-I../../Lib2-I../../Lib3-I../../Lib4-I. -I. -I../MyProject-I. -o wp2.o ../MyProject/wpmine.cpp

so as you can see, seems that gcc uses that param so... Any idea of why is it so heavy and how can I fix it? 所以你可以看到,似乎gcc使用那个参数......所以为什么它如此沉重,我该如何解决?

Thank you so much. 非常感谢。

Note: Their programs are made with eclipse and c++ basically while mine is made with Qt. 注意:他们的程序基本上是用eclipse和c ++编写的,而我的程序是用Qt编写的。 To run it they have isntalled some Qt libraries in the enterprise's product so another question is... could they run my program without that libraries installed? 为了运行它,他们已经在企业的产品中安装了一些Qt库,所以另一个问题是......他们可以在没有安装库的情况下运行我的程序吗? Just putting there the exe and calling it? 只是把那个exe并调用它?

Here are some tips to reduce executable size: 以下是减少可执行文件大小的一些提示:

  • You might want to use strip on your executable (in case something went wrong with compiler's -s flag) 您可能希望在可执行文件上使用strip (如果编译器的-s标志出现问题)

  • Compiling with -Os flag might reduce executable size slightly 使用-Os标志进行-Os可能会略微降低可执行文件大小

  • Reducing size of the data segment of the executable. 减小可执行文件数据段的大小。 Note that every constant (including string literals, static arrays initializers, etc) is stored inside executable and increases it's size: 请注意,每个常量(包括字符串文字,静态数组初始值设定项等)都存储在可执行文件中并增加它的大小:

     const char* str = "A very very long string"; // will bloat your executable BigDataType myData[] = { ... }; // will bloat your executable 
  • Moving embedded resources into external files (or even to the network). 将嵌入式资源移动到外部文件(甚至是网络)。 Embedded icons, images, strings, etc.) increase binary size dramatically. 嵌入的图标,图像,字符串等)显着增加二进制大小。 See QtResource QtResource

  • Reduce usage of the templated code. 减少模板化代码的使用。 Massive use of templates (along with their instantiation) is a well known reason of code bloating. 大量使用模板(以及它们的实例化)是众所周知的代码膨胀的原因。 This is a trade-off between code size and code beauty. 这是代码大小和代码美之间的权衡。

  • You might want to try CopperSpice , a fork of Qt, if it does any better. 如果它做得更好 ,你可能想尝试CopperSpice ,Qt的一个分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM