I'm new to qt.I made a very simple qt program, since I didn't had the commercial license I used dependency walker and added all the .dlls from my qtsdk folder to my release folder. It worked just fine.But when I checked its size it was very large.My question is how can I make it smaller.Also explain what is the difference between static and dynamic libraries and how it affects the size of an application.How many ways are there to make qt app smaller with out buying the commercial license.Any help is appreciated.
-
As it happens, I answered a question about static and dynamic libraries a week ago, see http://stackoverflow.com/a/21651275/1741542 – Olaf Dietsche Feb 13 '14 at 08:02
-
You don't need a commercial license for reducing the size of a binary. – Olaf Dietsche Feb 13 '14 at 08:03
-
1You have to for using QTs static linking. – Sebastian Lange Feb 13 '14 at 08:17
-
1You don't need a commercial licence to use static linking. You are, however, obliged to use the GPL licence, meaning your application MUST be open-source. – RobbieE Feb 13 '14 at 12:31
1 Answers
In general, there's nothing you can do to significantly reduce the size of the application and its dependencies. There are a few things I don't think you have considered or, if necessary can be done:
You don't need all Qt DLLs. Depending on which parts of Qt you used, you can leave out things like QtWebKit and others. This might well cut your applications redistribution size in half.
If it is your executable that is large, try compiling with options to optimize for size instead of speed. The final performance should be near or maybe even better than what the usual optimization does, depending on your application. This is
-Os
for GCC and/Os
for MSVC.Strip the DLLs and executables of debug symbols. Release builds should have this already done automatically. I do hope you're not complaining about the size of debug binaries...
Compact the binaries with something like UPX. This is only cosmetic though, and comes with some subtle drawbacks.
Recompile Qt with the above options, this might shave of 5-10% of the total Qt DLL size. You could also disable features (like unused Qt styles) you don't need, further reducing the size of the DLLs. But this is tedious and probably not worth it, as you'd need to recompile Qt whenever you update to the newest version.
That being said, if your code is GPL licensed, there's nothing stopping you from linking Qt statically. You will need to compile the static Qt libraries yourself, or find them somewhere. Generally, static linking will increase the size of the executable, but might allow the compiler to omit unused code from the image that would usually still be present in the DLL version. So yes, static linking might make your application's total size smaller.
-
1+1 for point 3. had a time where only debug builds was mady by myself :) – Zaiborg Feb 13 '14 at 08:58
-
-
@Dmitry thanks for the suggestion, I forgot about UPX. Added an extra option. – rubenvb Feb 13 '14 at 10:47
-
1maybe some tips about static linking, it reduced size just by 30%, I had expected much better. After .7z it is just -24%. – yalov Apr 04 '18 at 18:30