PDA

View Full Version : exe size with static linking



bcalmac
16th November 2006, 16:55
After playing a little with the QT/mingw 4.2.1 I was really concerned abot the size of examples/tutorial/t1 executable: 7.5MB (release, static linking)

Then I said it must be some poor configuration of gcc to keep people away from the open source version, so I installed the trial for Qt/Windows to see if the integration with the VC compiler can do better.

But with the trial it's not possible to recompile QT for static linking, so my question to QT/Windows users is:

What would be the exe size of the statically linked examples/tutorial/t1 with the VC compiler? Also, if you compiled all examples statically, what is the largest size of all examples?

thank you.

wysota
16th November 2006, 18:24
If you link statically, then you add all the code needed by the application, among it all the code from all Qt libraries used. If classes used have many dependencies, the resulting code can be quite big. If you want smaller code, try compiling with -Os which should reduce the size a little.

bcalmac
16th November 2006, 19:00
Hi wysota,

My precise concern is that the size of the exe is about the size of the QtCore + QtGUI libraries, which means that a simple button requires to link the whole framework, which doesn't seem right.

For comparison (if needed) a "Hello world" MFC application is below 100K, it just links a minimal set of used functions from the library. Is QT designed in such a way that a simple button has a dependency on all the functions in the library?

thanks for the clarification,

Bogdan Calmac.

wysota
16th November 2006, 21:29
My precise concern is that the size of the exe is about the size of the QtCore + QtGUI libraries, which means that a simple button requires to link the whole framework, which doesn't seem right.
It links more than just Qt libraries. Probably you also have the whole mingw legacy somewhere in your app :)


For comparison (if needed) a "Hello world" MFC application is below 100K, it just links a minimal set of used functions from the library.
You can't compare it like that, the frameworks are completely different.


Is QT designed in such a way that a simple button has a dependency on all the functions in the library?

You're not using the button only. You're using QApplication and its all dependencies, along with sql, image and probably other plugins. Probably MSVC does some optimisations which are not turned on in MinGW. First thing I would do is to pass -Os to mingw. The second thing would be to strip the application from symbols (I don't know how it is done on Windows, under U*ix you simply write "strip appbinaryname" and you get a much smaller binary. BTW. You should also compile Qt with -Os if you're after minimising the binary size.

BTW2. It is "Qt", not "QT". The latter is Apple technology.

bcalmac
16th November 2006, 22:44
Hi wysota,

I'm coming from the java world back to C/C++ for small footprint and performance, and 7.5MB for a statically linked application with a "Hello world" looks huge to me. Aside from compiler optimizations and stripping the binary (which wouldn't bing the size to 300-500K) the issue that I see here is that somehow using QButton and QApplication brings into the executable the code for the whole framework.

A linker would add to the executable only those functions from libraries that are used in the object file being linked. So is Qt designed in such a way that everything depends on everything and using a couple of classes brings into the exe the code for the whole framework?

thanks,

Bogdan.

wysota
17th November 2006, 00:29
Aside from compiler optimizations and stripping the binary (which wouldn't bing the size to 300-500K)
Well... I have seen a 30MB application go down to 900k after stripping.


the issue that I see here is that somehow using QButton and QApplication brings into the executable the code for the whole framework.
As I said, you might be "inheriting" some other code beside the framework.


A linker would add to the executable only those functions from libraries that are used in the object file being linked. So is Qt designed in such a way that everything depends on everything and using a couple of classes brings into the exe the code for the whole framework?

As Qt is a framework and moreover an object oriented one, probably many things depend on many other. In that way - yes, it is designed that way. But this is only a general answer, as without any tests it is hard to say anything close to being precise. Building a button cosisting of only a button doesn't mean anything, as you can construct a button in many ways and run it using many differently compiled Qt libraries. Not knowing your exact configuration I can only assume or guess. Qt is not like MFC - get all in single dll without any way to configure. You can add or remove components and doing that adds or removes dependencies. For example - you can compile Qt with or without STL support which either causes the stdc++ library to be added or removed as a dependency and by using a QString in your application (I believe you are using a QString for the button) you add a dependency on std::string, which adds more dependencies, etc. even if stdc++ lib is not part of Qt framework itself. If you use have built Qt with features like rtti, exceptions, etc. you also increased its size and caused more code to be included into your app. If you are using a button, you are also using pixmap support which yields dependencies for libraries like libjpeg, libpng, etc. If they are statically compiled too, they'll be statically linked, bloating your app even more (no matter that you actually don't use pixmap yourself, but the button class contains support for it). So without knowing which libs were linked statically and which were linked dynamically, you can't say what kind of code is linked into your application.

If you are interested how does it look like in reality, then please make some tests (but make all that can be done to assure the tests are valid and in regard to the environment) and share the results with us - I'd also be interested in knowing how much dependencies does a simple Qt application contain and how big will my app be if I want to link it statically and how much will I gain by turning some features off during Qt compilation. Influence of compiler switches and the tool chain itself sounds very interesting too.

Cheers!

bcalmac
17th November 2006, 14:34
All right, then I'll do some more investigation with mingw and post the results.