PDA

View Full Version : bundling parts of qt with application



numerodix
15th September 2006, 14:35
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..

high_flyer
15th September 2006, 15:20
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...

numerodix
15th September 2006, 15:35
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?


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?


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.

high_flyer
15th September 2006, 15:49
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.

Valheru
17th September 2006, 16:59
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?

Chicken Blood Machine
17th September 2006, 21:02
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.

stevey
19th September 2006, 02:30
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

numerodix
19th September 2006, 21:07
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?

Chicken Blood Machine
19th September 2006, 21:41
I'm not sure how you do it on Windows, but on UNIX, it's just 'strip exename'

ZB
19th September 2006, 22:04
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.

Valheru
19th September 2006, 22:53
Specifying
-s 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.

numerodix
19th September 2006, 23:31
Specifying
-s 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.

Chicken Blood Machine
19th September 2006, 23:35
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?

numerodix
20th September 2006, 02:21
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.