Results 1 to 7 of 7

Thread: exe size with static linking

  1. #1
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question exe size with static linking

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: exe size with static linking

    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.

  3. #3
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: exe size with static linking

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: exe size with static linking

    Quote Originally Posted by bcalmac View Post
    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.

  5. #5
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: exe size with static linking

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: exe size with static linking

    Quote Originally Posted by bcalmac View Post
    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!

  7. The following user says thank you to wysota for this useful post:

    bcalmac (17th November 2006)

  8. #7
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: exe size with static linking

    All right, then I'll do some more investigation with mingw and post the results.

Similar Threads

  1. static & dynamic linking
    By mickey in forum General Programming
    Replies: 6
    Last Post: 11th June 2010, 08:57
  2. static linking issue
    By ashwini in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2006, 12:40
  3. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  4. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14
  5. Replies: 4
    Last Post: 20th February 2006, 09:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.