Building against Static Qt for portability

I ported my tip calculator from Android to Qt on Centos and tried to run it on a RHEL4 host and got the following:

>./tipCalc.Dynamic

Floating exception

tipCalc was only 40kB and ldd revealed it was trying to load shared libraries I didn’t have on that host:

>ldd tipCalc.Dynamic
libQtGui.so.4 => /software/qt/qt/lib/libQtGui.so.4 (0×006d6000)
libQtCore.so.4 => /software/qt/qt/lib/libQtCore.so.4 (0×00110000)

To build a static app required 2 steps:

1.  Rebuild Qt libraries statically:

>configure -static -prefix /software/qtStatic/ -make libs -make tools -release -nomake examples -nomake demos

>gmake

the demos and examples take a long time to compile (and diskspace, I ran out of it twice in Vmware) so I left them out with –nomake

2. Add the following options to the project .pro file:

CONFIG += staticlib
CONFIG += release

Now tipCalc.Static is 12MB but doesn’t require shared Qt libraries.