Qt-interest Archive, August 2007
Small Static Executables
Pages: Prev | 1 | 2 | Next
Message 1 in thread
Hey all,
I'm learning Qt with the hope of using it for an upcoming product where I
work. One problem is that, for the app I want to use it for, size matters a
lot. I'd really need a statically linked Qt app to be no more than a
megabyte at the outside. Instead, even with dead code stripping and a few
other options, the smallest I can get a "Hello, world!" app that does
nothing other than display a QLabel is about 7.5 MB MB, both on Windows and
on Mac. Using a compressor thunk on top of that only trims it to about 3-4
MB. Is this normal, or am I missing something obvious? Intuitively, the
application should be far smaller, but I can see where dependencies within
Qt or deficiencies within GCC's linker may make the actual minimum higher
than it needs to be.
Thanks much for any help you can provide.
--Benjamin
Message 2 in thread
Mandag 20 august 2007 18:04 skrev Benjamin Pollack:
> Hey all,
>
> I'm learning Qt with the hope of using it for an upcoming product where I
> work. One problem is that, for the app I want to use it for, size matters a
> lot. I'd really need a statically linked Qt app to be no more than a
> megabyte at the outside. Instead, even with dead code stripping and a few
> other options, the smallest I can get a "Hello, world!" app that does
> nothing other than display a QLabel is about 7.5 MB MB, both on Windows and
> on Mac. Using a compressor thunk on top of that only trims it to about 3-4
> MB. Is this normal, or am I missing something obvious? Intuitively, the
> application should be far smaller, but I can see where dependencies within
> Qt or deficiencies within GCC's linker may make the actual minimum higher
> than it needs to be.
You need to start compiling Qt with only just the features you need. First, I
would start by disabling everything you can in the configuration of the
build. If that is not enough, mail us here again, and we will bring out the
big guns :-)
You can read about the build process here:
http://doc.trolltech.com/4.3/installation.html.
I hope this helps.
Bo Thorsen.
--
[ signature omitted ]
Message 3 in thread
> build. If that is not enough, mail us here again, and we will
> bring out the big guns :-)
Since the OP stated that it was not enough, i'm wondering where the big
guns are ;-)
Cheers,
Peter
--
[ signature omitted ]
Message 4 in thread
On onsdag den 22. August 2007, Peter Prade wrote:
> > build. If that is not enough, mail us here again, and we will
> > bring out the big guns :-)
>
> Since the OP stated that it was not enough, i'm wondering where the big
> guns are ;-)
Oooh - a dare :-)
Well, I actually did an attempt at this on Linux, and I can briefly tell what
I did and what came of it.
First, I just compiled qt and made a simple qt helloworld (with a qlabel as a
window). The binary was ~8.5M. A strip -s on it brought me down to 7.3M.
Then I recompiled Qt with pretty much every single -no-featureX, and I came
down to a stripped binary at 6M. Still big.
Then I started hacking away inside Qt. You open src/corelib/global/qfeatures.h
in a text editor. Or start up the qconfig that's available sometimes (I have
it in my commercial edition) which works on this file. And then you start
cutting features from Qt. If you don't need QComboBox, remove the // on the
#define QT_NO_COMBOBOX line, and it disappears completely. Warning: It's
going to take you a while to actually get a usable and compilable Qt library
once you start doing this. You may end up having to edit Qt sources for it to
compile. This define system is good, but it's nowhere near complete. There
are things that might depend on features and not be ifdeffed out.
With this hacking away, I got a binary that was 3.1M big. That's a bit more
than a third of the size of the original binary. Not bad, but I still think
it can get even smaller. That's the reason I didn't answer this yet, because
I wanted to go even lower.
Things I would try next include a lot of compiler and linker flags, and
getting rid of even more unnecessary Qt stuff.
Now, if we look at OPs last mail:
"I followed Gordon's suggestions above, adding those linker options to the
qmakespec, and rebuilt Qt. The configure command I used
was "-static -release -no-qt3support -no-style-cde -no-style-motif
-no-style-cleanlooks -no-style-plastique". I then rebuilt hello.exe statically
against the release libraries. The new executable is 5.4 MB--a huge
improvement from the 7.5 MB of the original, but not quite good enough. Using
UBX, I can cut that down to about 2.6 MB--still more than twice as large as
my maximum size."
He used only a few of the options above, and still got down to 2.6 MB. It
would be quite interesting to see how far down he would get with the extra
ideas I tried. Also, I'm completely certain he would get better results with
gcc on Mac and VS2005 on Windows than he does with mingw.
To those interested, here is the Linux configure options I used:
./configure -prefix ../build -static -release -nomake examples -nomake
demos -no-qt3support -no-exceptions -no-accessibility -no-stl -no-gif -no-libtiff -no-libmng -no-nis -no-qdbus -no-openssl -no-opengl -no-sm -no-tablet -no-glib -no-fontconfig -no-xrender -no-xrandr -no-xfixes -no-xcursor -no-xinerama -no-xshape -no-sm -no-libtiff -no-gif -no-cups -no-sql-mysql -no-sql-psql -no-sql-sqlite -no-sql-sqlite2
I hope this was at least interesting, if not useful :-)
Bo.
--
[ signature omitted ]
Message 5 in thread
> Von: Bo Thorsen
> Betreff: Re: Small Static Executables
> On onsdag den 22. August 2007, Peter Prade wrote:
> > > build. If that is not enough, mail us here again, and we will
> > > bring out the big guns :-)
> >
> > Since the OP stated that it was not enough, i'm wondering where the big
> > guns are ;-)
>
<snip>
> ideas I tried. Also, I'm completely certain he would get better results
> with
> gcc on Mac and VS2005 on Windows than he does with mingw.
>
Our qt-based kdewindows-installer (with gui, uses also qtnetwork) only needs ~1.3MB. It's compiled with all unnneded qt features disabled, but includes the msvc runtime (so it should get a little bit smaller when you want to depend on msvcrtXX.dll). We pack it with the executable packer upx (upx.sf.net) in lzma mode.
Christian
--
[ signature omitted ]
Message 6 in thread
> Then I started hacking away inside Qt. You open
> src/corelib/global/qfeatures.h
> in a text editor. Or start up the qconfig that's available
> sometimes (I have
> it in my commercial edition) which works on this file. And
> then you start
> cutting features from Qt. If you don't need QComboBox, remove
> the // on the
> #define QT_NO_COMBOBOX line, and it disappears completely.
Nice, this looks like the way to go! And not as hard is thought it would
be :-)
In Qt 4.3.1, there is also a qfeatures.txt in the same directory that
explains some of the dependencies, and qconfig.h with a bunch of
derivates (qconfig-small.h etc.) this also looks promising.
Cheers,
Peter
--
[ signature omitted ]
Message 7 in thread
Well, static Qt apps (that use gui) tend to be rather large. this is
normal.
Qt 4 is now divided into parts that you can leave out (like xml, sql,
etc.) but all gui elements still remain in one lib. (you can't specify
that you only need a label, you get all the gui elements and there is no
easy way around this)
If you really need to strip this down, you'll need to make your own qt
libs that remove code that you don't need. I guess this would be a
difficult task.
Cheers,
Peter
> -----Original Message-----
> From: Benjamin Pollack [mailto:benjamin.pollack@xxxxxxxxx]
> Sent: Monday, August 20, 2007 6:05 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Small Static Executables
>
>
> Hey all,
>
> I'm learning Qt with the hope of using it for an upcoming
> product where I work. One problem is that, for the app I want
> to use it for, size matters a lot. I'd really need a
> statically linked Qt app to be no more than a megabyte at the
> outside. Instead, even with dead code stripping and a few
> other options, the smallest I can get a "Hello, world!" app
> that does nothing other than display a QLabel is about 7.5 MB
> MB, both on Windows and on Mac. Using a compressor thunk on
> top of that only trims it to about 3-4 MB. Is this normal, or
> am I missing something obvious? Intuitively, the application
> should be far smaller, but I can see where dependencies
> within Qt or deficiencies within GCC's linker may make the
> actual minimum higher than it needs to be.
>
> Thanks much for any help you can provide.
>
> --Benjamin
>
>
--
[ signature omitted ]
Message 8 in thread
"Peter Prade" <prade@xxxxxxxxxxx> wrote on 08/20/2007 10:14:09 AM:
# Well, static Qt apps (that use gui) tend to be rather large. this is
# normal.
# Qt 4 is now divided into parts that you can leave out (like xml, sql,
# etc.) but all gui elements still remain in one lib. (you can't specify
# that you only need a label, you get all the gui elements and there is no
# easy way around this)
#
# If you really need to strip this down, you'll need to make your own qt
# libs that remove code that you don't need. I guess this would be a
# difficult task.
The GNU linker doesn't pull in the entire library, it is smarter than
that. It includes only the files that are used (as opposed to only
the *functions* that are used, like e.g. Microsoft's compiler).
That said, I'd make sure that, as already suggested, you turn off
every single feature you don't need in the Qt build, as it will
reduce internal dependencies within Qt (and thus reduce the files
that will get included).
Lastly, there are some gcc and ld switches that may help:
-Os (instead of -O2)
-fmerge-all-constants
-fno-default-inline
-fno-inline
possibly -ffunction-sections, -fdata-sections, and -Wl,--gc-sections
You will have to modify the qmakespec file for your platform in
order to do this. Do this *before* building Qt, so that Qt
itself will get built with the changed settings.
See http://gcc.gnu.org/onlinedocs/gcc-4.2.1
/gcc/Optimize-Options.html#Optimize-Options
for reference on these options. (The --gc-sections option is a
linker option - see 'info ld' instead.)
--
[ signature omitted ]
Message 9 in thread
Hi,
>
> The GNU linker doesn't pull in the entire library, it is smarter than
> that. It includes only the files that are used (as opposed to only
> the *functions* that are used, like e.g. Microsoft's compiler).
>
Just curious... Although you don't say so explicitly, it seems like
you're implying that this is better then the MS approach.
I have no idea which is better (in terms of final executable size), but
surely pulling in individual functions, rather than pages, would lead to
a smaller executable? (if perhaps at the cost of a longer linking time).
Thanks,
--
[ signature omitted ]
Message 10 in thread
Reading Gordon, I had the same thougth.
Gordon, did we understand properly your writings?
Regards
Alle 18:49, lunedì 20 agosto 2007, Thomas Richards ha scritto:
> Hi,
>
> > The GNU linker doesn't pull in the entire library, it is smarter than
> > that. It includes only the files that are used (as opposed to only
> > the *functions* that are used, like e.g. Microsoft's compiler).
>
> Just curious... Although you don't say so explicitly, it seems like
> you're implying that this is better then the MS approach.
>
> I have no idea which is better (in terms of final executable size), but
> surely pulling in individual functions, rather than pages, would lead to
> a smaller executable? (if perhaps at the cost of a longer linking time).
>
>
>
> Thanks,
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 11 in thread
Thomas Richards schrieb:
> Hi,
>
>> The GNU linker doesn't pull in the entire library, it is smarter than
>> that. It includes only the files that are used (as opposed to only
>> the *functions* that are used, like e.g. Microsoft's compiler).
>>
>
> Just curious... Although you don't say so explicitly, it seems like
> you're implying that this is better then the MS approach.
No, only including the needed functions (as is obviously done by the MS
compiler) is off course better; including the whole *.cpp file (as
obviously done by the gcc), that is the whole compilation unit,
naturally also includes all the non-needed functions which adds
unnecessary size to the executable.
That's how I interpreted Gordon's posting.
Cheers, Oliver
--
[ signature omitted ]
Message 12 in thread
Take a look at the QTSRC/tools/qconfig application that is shipped with
QT.
I have been using it for just this reason with an embedded app, and it
really helps you shrink it down in size
Scott
> -----Original Message-----
> From: Till Oliver Knoll [mailto:oliver.knoll@xxxxxxxxxxx]
> Sent: Monday, August 20, 2007 1:19 PM
> To: Qt Interest List
> Subject: Re: Small Static Executables
>
> Thomas Richards schrieb:
> > Hi,
> >
> >> The GNU linker doesn't pull in the entire library, it is smarter
than
> >> that. It includes only the files that are used (as opposed to only
> >> the *functions* that are used, like e.g. Microsoft's compiler).
> >>
> >
> > Just curious... Although you don't say so explicitly, it seems like
> > you're implying that this is better then the MS approach.
>
> No, only including the needed functions (as is obviously done by the
MS
> compiler) is off course better; including the whole *.cpp file (as
> obviously done by the gcc), that is the whole compilation unit,
> naturally also includes all the non-needed functions which adds
> unnecessary size to the executable.
>
> That's how I interpreted Gordon's posting.
>
> Cheers, Oliver
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 13 in thread
On 8/20/07, Scott Aron Bloom <scott@xxxxxxxxxxxx> wrote:
>
> Take a look at the QTSRC/tools/qconfig application that is shipped with
> QT.
In Qt 4.3.0 Open-Source Edition, I don't seem to have a qconfig application
there. Does it only come with the commercial version?
--Benjamin
Message 14 in thread
>
> In Qt 4.3.0 Open-Source Edition, I don't seem to have a qconfig
> application there. Does it only come with the commercial version?
>
Unfortunately, it's only built when you configure with "qt3support".
Caleb
--
[ signature omitted ]
Message 15 in thread
I always wind up building it on its own
________________________________
From: Caleb Tennis [mailto:caleb@xxxxxxxxxxxx]
Sent: Mon 8/20/2007 2:04 PM
To: Qt Interest List
Subject: Re: Small Static Executables
>
> In Qt 4.3.0 Open-Source Edition, I don't seem to have a qconfig
> application there. Does it only come with the commercial version?
>
Unfortunately, it's only built when you configure with "qt3support".
Caleb
--
[ signature omitted ]
Pages: Prev | 1 | 2 | Next