Results 1 to 8 of 8

Thread: lightweight static linking qt?

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default lightweight static linking qt?

    So I statically linked Qt to my simple app that sends a few messages over sockets then shuts down. But the resulting executable is 850KB!! (release build, no symbols) I was wondering if there might be any compiler or preprocessor options to recompile Qt, to try to cut the executable size down to below 500kb, make it a little more lightweight. I am only linking in QtCore.lib and QtNetwork.lib.
    Last edited by gfunk; 2nd April 2007 at 22:43.
    Software Engineer



  2. #2
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: lightweight static linking qt?

    I guess you could always try to recompile Qt with size-optimization (as opposed to speed-optimization). But yeah, that would be a lot to do compared to setting a define. Sorry I know none Maybe looking through the Qt sources will reveal something? :-)
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

  3. #3
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: lightweight static linking qt?

    Well I snooped around in src\corelib\global and found qconfig-large.h, qconfig-medium.h, qconfig-small.h, qconfig-minimal.h, as well as a file qfeatures.h. I guess I'm just wondering if including these macros are sufficient to shrink my executable, or if I need to recompile the Qt libs, or what the recommended way of doing this is.
    Software Engineer



  4. #4
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: lightweight static linking qt?

    so I included qconfig-minimal.h and got rid of some of the compile errors by undefining
    QT_NO_TEXTSTREAM and QT_NO_SETTINGS. But I got no change in executable size. Maybe VC already does a good job of truncating the unused functions. I note that QtCore.lib is 14MB and QtNetwork about 1.4MB, so maybe I should just be happy that it's less than 1MB and hope no one notices.
    Software Engineer



  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: lightweight static linking qt?

    Under Unix and Mac, you can "strip" a statically linked binary. I don't know if your "release, no symbols" is the equivalent.

    Qt/Embedded (qtopia) has build options to define out unwanted parts of the library. These defines are in the Qt source code, so you can use them. But the Qt configure script doesn't support them, so you will have to hack a bit on the project files to get a minimal build.

  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: lightweight static linking qt?

    You can also pack the resulting binary with solutions like UPX. Stripping down things like STL support, rtti, exceptions from Qt may also reduce the binary size.

  7. #7
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: lightweight static linking qt?

    With the msvc compiler you can also enable function level linking and remove unused symbols/functions from the code.

    Compiler flags + "/Gy"
    Linker flags + "/OPT:ICF /OPT:REF"

    If not already done

  8. #8
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: lightweight static linking qt?

    Quote Originally Posted by gri View Post
    With the msvc compiler you can also enable function level linking and remove unused symbols/functions from the code.
    Compiler flags + "/Gy"
    Linker flags + "/OPT:ICF /OPT:REF"
    If not already done
    The same can be done while using gcc by passing the options

    Qt Code:
    1. -fdata-sections -ffunction-sections -Wl,--gc-sections
    To copy to clipboard, switch view to plain text mode 

    The last one is actually an option --gc-sections to the linker ld, but gcc passes that on when we prefix it by -Wl,
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

Similar Threads

  1. static & dynamic linking
    By mickey in forum General Programming
    Replies: 6
    Last Post: 11th June 2010, 08:57
  2. Replies: 16
    Last Post: 23rd May 2008, 10:12
  3. static linking issue
    By ashwini in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2006, 12:40
  4. 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
  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.