This article will show you how to build Qt, the popular C++ framework from Nokia, so that it is both small and, if you prefer, available for static linking. Your Qt applications will be smaller, possibly faster, and can be distributable as a single executable.
Also answered: How small can Intel’s C++ compiler make a large library? How does Microsoft fare? Three compilers (settings tuned for small file output) and their resulting code size is compared.
Make your entire Qt application work entirely from a single file.
I was downloading Ubuntu Netbook Remix for my EeePC 900A and found that it’s installer is not a CD image, but a raw image meant to be written to a USB FLASH drive. After downloading their handy image writer, I found that this simple utility came with quite a few support files, including a surprising 13.5MB of .dlls.
This image writer tool was written using Nokia’s Qt software, which allows easy development and distribution for all the major platforms from a single C++ source base. This program was compiled in the same way most Windows software is today — with “dynamic linking”, requiring the Qt libraries, among others, be shipped with the program as separate files.
This is fine for large software projects, but it’s a little cumbersome for small tools like this one. Many programs can be distributed such that all necessary files are built into the executable in a process called static linking. Sometimes it is nice to be able to download just the program itself and not have to worry about making sure various DLLs are included (though setting up an installer largely eliminates this problem).
Static linking has its advantages and disadvantages, but when not done, running a program unaccompanied by even one support file will result in a cryptic error for the user:
These 4 steps are all you need to make your entire project result in a single, easy-to-distribute .EXE file:
- Complete your Qt project using normal debug libraries.
- Compile the Qt libraries for static linking (needs to be done only once).
- Add the necessary lines of code to include any Qt plugins you may need.
- Compile your release version with the static libraries.