Reputation: 2609
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.
Upvotes: 3
Views: 1835
Reputation: 76529
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.
Upvotes: 8