So, you have developed a nice app using Qt library with Qt Creator and now you want to share it (or deliver it to a client), but you don't want to make them install the whole Qt library in their computer?
What you need is to put everything into a single executable file, into other words, you need to link statically the Qt library. But how to do this the default one is shared? - You have to recompile it (don't panic now, it's easy), but statically this time, so thus Qt Creator will be able to link you program statically during compile (or to be more precise, link) time.
Don't worry, it ain't rocket science, in a few steps you will able to happily build your first single file applications =D.
First Step - Download the most recent Qt library source code by clicking on this link.
Second Step - Unpack it to an easy-to-find location in your user folder. Eg. /home/myUser/qtLibrary
Third Step - Create a new folder where the statical library will be stored. Eg. /home/myUser/qtStaticLib
Fourth Step - Open up a terminal window. Type:
cd /home/MyUser/qtLibrary (enter key)./configure -prefix /home/MyUser/QtLibs/qtStaticLib -largefile -static -qt-libjpeg -qt-libpng -qt-libmng -qt-zlib -debug-and-release -phonon -phonon-backend -svg -dbus -script -qt-sql-mysql -multimedia -audio-backend -opengl -stl -glib -xrender -xshape -xcursor -xinput -xrandr -xfixes -xsync -xkb -xmlpatterns -fontconfig -glib -mitshm -sm -pch -nis -cups -gtkstyle -nomake demos -nomake examples -nomake tools (enter key)
Probably this step WILL fail, and messages like Phonon support cannot be enabled due to functionality tests! will be shown.
This is because you don't have all the libraries which are necessary to build Qt. For the example given above, you will need libgstreamer0.10-dev. Just open your package manager (Synaptic if you're using Ubuntu), search and download it. Run step four again.
Here's a list of the libraries that were missing for me:
libgstreamer0.10-dev, libgstreamer-plugins-base0.10-dev, libxext-dev, libxrender-dev, libmysql++-dev, libxcursor-dev, libxfixes-dev, libxi-dev, libxrandr-dev, libgtk2.0-dev, freeglut3-dev, libasound2-dev, libxv-dev, libdbus-1-dev, libcups2-dev.
If ./configure passes without any complaints, proceed to the next step.
Fifth Step - Type in terminal:
make -j 2 (enter key) PS. -j 2 tells gcc to use two threads to compile, so if you have a CPU with two cores it will use both. Replace the number with the number of cores that you have. Now sit down and relax, it will take a while.
Sixth Step - Congratulations! You have successfully compiled Qt library statically! Now you must make Qt Creator use it instead of the shared standard version.
- Close that terminal that you opened before.- Open your Qt Creator.
- Go to menu Tools -> Options -> Qt 4 (tab).
- Click on the plus signal button and then browse the qmake executable inside /home/myUser/qtStaticLib.
- Name it as you like, I typed Qt Statical.
- Click the Ok button.
Seventh Step - Nice! Your Qt Creator knows about the existence of another library. Finally all that is left is to make your project use it instead of the standard one.
- Open your project.
- Click on the Projects button on the left.
- Change Qt Version to Qt Statical.
- Finally, add the following to your .pro file:
CONFIG += static.
- Recompile your project. Check out how the executable file size increased. DONE!