Results 1 to 14 of 14

Thread: bundling parts of qt with application

  1. #1
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    1

    Default bundling parts of qt with application

    This is a question about static linking, but not the same one that is answered in the on-site Wiki and elsewhere. I have a cross platform application in mind. And I want to distribute a single binary. I'd like the binary to be as small as possible, it won't be doing very complicated things.

    Now as far as I understand qt, all the library modules are compiled into libraries per module. So QtNetwork is found in libQtNetwork.so.4.1.4. But I don't need all of QtNetwork, I only need a small subset of it. And with the other modules it would be the same story. So how about copying parts of the qt source (only what I need) into my project dir and compiling the source as if it were part of my project?

    This would reduce the size of the binary, wouldn't it? But is this a good idea? The question is how would I then build the project? Could I still use qmake (I would like to on account of it doing some nice platform-specific handling)?

    I would like a build system that would build a static binary for every platform from the same source..

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: bundling parts of qt with application

    There are two issues here:
    1. Technical
    2. Legal

    The technical issue I think, is not as simple as you describe it.
    Taking out just the functionalities you need, may prove to be harder and complexer then you might think.
    It is very likely that the end functionalities that you need are dependent on other more low level functionalities in the specific Qt module you are dealing with.
    I'd say that purely theoretical this is possible, but I don't think it is doable in any practical way, that would benefit you more then just to link with the whole module.

    If the functionalities you are talking about are really "local" (in terms of dependency) and basic, there is a good chance you can find them as independent GPL/public-domain code, after all, what would be the advantage of devouring Qt, if you can have it clean from another source?

    The legal issue ofcourse is, that if you are talking about the GPL/QGPL version of Qt, I am not sure you are allowed to do that, and if you are, I am not sure what it means in terms of you needing to supply the full Qt code, but I am no lawyer, better let others who know more then me on this issue to answer...

  3. #3
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    1

    Default Re: bundling parts of qt with application

    Quote Originally Posted by high_flyer
    There are two issues here:
    1. Technical
    2. Legal

    The technical issue I think, is not as simple as you describe it.
    Taking out just the functionalities you need, may prove to be harder and complexer then you might think.
    It is very likely that the end functionalities that you need are dependent on other more low level functionalities in the specific Qt module you are dealing with.
    I'd say that purely theoretical this is possible, but I don't think it is doable in any practical way, that would benefit you more then just to link with the whole module.
    I don't understand what the problem is. Would it not be enough to just include all the source files that I use (and all their dependencies)? Are you implying there would be some platform specific issues not handled with this approach?

    Quote Originally Posted by high_flyer
    If the functionalities you are talking about are really "local" (in terms of dependency) and basic, there is a good chance you can find them as independent GPL/public-domain code, after all, what would be the advantage of devouring Qt, if you can have it clean from another source?
    Right, but Qt is inherently cross platform and thus it would be nice to use something that is known to work well. Afterall, that's the benefit of Qt in the first place, right?

    Quote Originally Posted by high_flyer
    The legal issue ofcourse is, that if you are talking about the GPL/QGPL version of Qt, I am not sure you are allowed to do that, and if you are, I am not sure what it means in terms of you needing to supply the full Qt code, but I am no lawyer, better let others who know more then me on this issue to answer...
    I don't know anything about the QPL licence, but under GPL it's perfectly alright to take part of some code and redistribute it. My application would be GPL as well.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: bundling parts of qt with application

    I don't understand what the problem is. Would it not be enough to just include all the source files that I use (and all their dependencies)? Are you implying there would be some platform specific issues not handled with this approach?
    It depends.
    If you are lucky yes.
    Chances are however no.
    I think you will find that the source you are using will depend on other headers and sources.
    Basically it comes down to specifics - what it is you want to extract, and how it is implemented in Qt.

  5. #5
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: bundling parts of qt with application

    If you are talking about Windwoes, then just statically compile and strip the binary, then use UPX to compress the executable. That's the whole idea of stripping a binary in the first place, isn't it?

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: bundling parts of qt with application

    Quote Originally Posted by numerodix View Post
    This is a question about static linking, but not the same one that is answered in the on-site Wiki and elsewhere. I have a cross platform application in mind. And I want to distribute a single binary. I'd like the binary to be as small as possible, it won't be doing very complicated things.

    Now as far as I understand qt, all the library modules are compiled into libraries per module. So QtNetwork is found in libQtNetwork.so.4.1.4. But I don't need all of QtNetwork, I only need a small subset of it. And with the other modules it would be the same story. So how about copying parts of the qt source (only what I need) into my project dir and compiling the source as if it were part of my project?
    What you are talking about is static linking but in an overly-complicated way. Building Qt statically and compiling your program against the static libraries will achieve exactly what you are talking about (and you can use qmake for this), without you having to figure out all of the intricate dependencies.

    Then (as someone else mentioned) you can strip the resultant binary to make it even smaller.
    Save yourself some pain. Learn C++ before learning Qt.

  7. The following user says thank you to Chicken Blood Machine for this useful post:

    numerodix (19th September 2006)

  8. #7
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: bundling parts of qt with application

    You can either include the entire module, or explicitly include only the header files containing the functions you're calling.
    Then only those corresponding libs will be included.
    But note that if those libs depend on other libs, then they will also be built into the final binary.


    Stevey

  9. #8
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    1

    Default Re: bundling parts of qt with application

    Quote Originally Posted by Chicken Blood Machine View Post
    What you are talking about is static linking but in an overly-complicated way. Building Qt statically and compiling your program against the static libraries will achieve exactly what you are talking about (and you can use qmake for this), without you having to figure out all of the intricate dependencies.

    Then (as someone else mentioned) you can strip the resultant binary to make it even smaller.
    Right, that's exactly what I wanted. I'm a bit of a newbie with the whole build process, I was under the impression that all stripping does is remove debug symbols (if they are present). How do I strip anyway?

  10. #9
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: bundling parts of qt with application

    I'm not sure how you do it on Windows, but on UNIX, it's just 'strip exename'
    Save yourself some pain. Learn C++ before learning Qt.

  11. #10
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: bundling parts of qt with application

    Both MingW (a Win32 port of GCC) and MSVC, the two most popular compiler suites for Windows, will remove abundant symbols during compile/link-time. You can also use the strip-tool which is included in the MingW-suit.

  12. #11
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: bundling parts of qt with application

    Specifying
    Qt Code:
    1. -s
    To copy to clipboard, switch view to plain text mode 
    as one of the linker (compiler? I forget which) options will strip the binary. And if you are planning to distribute the binary, you won't want to distribute a version with debug info as that makes the binary enourmous. A statically linked Qt binary that I have now weighs in at 6 MB, versus the 45 MB of the debug version. Users don't need debug info.

  13. #12
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    1

    Default Re: bundling parts of qt with application

    Quote Originally Posted by Valheru View Post
    Specifying
    Qt Code:
    1. -s
    To copy to clipboard, switch view to plain text mode 
    as one of the linker (compiler? I forget which) options will strip the binary. And if you are planning to distribute the binary, you won't want to distribute a version with debug info as that makes the binary enourmous. A statically linked Qt binary that I have now weighs in at 6 MB, versus the 45 MB of the debug version. Users don't need debug info.
    Yes, I wrote a small hello world using a class from QtNetwork and the stripped binary is 1.5mb. I imagine it will be quite a bit bigger once I start adding gui, but still it helps.

  14. #13
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: bundling parts of qt with application

    Quote Originally Posted by numerodix View Post
    Yes, I wrote a small hello world using a class from QtNetwork and the stripped binary is 1.5mb. I imagine it will be quite a bit bigger once I start adding gui, but still it helps.
    I take it that it does more than just print "Hello World" given that you are using QtNetwork and not just QtCore?
    Save yourself some pain. Learn C++ before learning Qt.

  15. #14
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    1

    Default Re: bundling parts of qt with application

    Quote Originally Posted by Chicken Blood Machine View Post
    I take it that it does more than just print "Hello World" given that you are using QtNetwork and not just QtCore?
    Yes, it looks up the IP for a given hostname, so just a simple "hello world" style network test.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 18:51
  2. Gnome makes application crash
    By regix in forum Qt Programming
    Replies: 35
    Last Post: 18th August 2006, 19:44
  3. How to install my own application in QUnitTest
    By Artschi in forum Qt Programming
    Replies: 3
    Last Post: 18th July 2006, 16:05
  4. Replies: 5
    Last Post: 24th April 2006, 15:42
  5. Replies: 3
    Last Post: 31st March 2006, 18:38

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.