QT under the static compile Qt, according to my experience, if according to the kind of windows under the Official SDK installed directly after the file to compile is not feasible, need to download QT source package directly, At present, the source of Nokia is called QT-EVERYWHERE-OPENSOURCE-SRC tar package, to the online search, obediently, most people compiled this package actually took 12-13 hours! However, based on my experience of statically compiling QT under Windows, many of these things can be done without compiling, and in the end it took me about 40 minutes to compile everything. If you are directly using the Official SDK installation, then you have a dynamic library, and now you are compiled through the source package, so long as you compile a static library, because you already have a dynamic library, you even need to compile static release library is enough, who will be in peacetime compile time to use the kind of waste time static compile? When the product to be deployed to other machines, QT need to use the time to connect on it, so that other content, such as the dynamic library of Demo,examples are still available, install two version will not spend too much time, not the two worlds? Long story short, now say the installation step.
1. Download the Qt-everywhere source package online,
If you just want the library, you can also find the version you need at the following URL.
Http://www.linuxidc.net/thread-2237-1-1.html
2. Unzip to your target directory
3. Select the part to compile via configure.
You can modify the qt_default_build_parts= "Libs tools examples Demos Docs translations" in the Configure file by directly modifying the Examples,docs, Demos all removed (I only removed these three, theoretically if the dynamic version is installed, tools and translations (this is linguist) can also be removed. You can also add –no-make * * * (here is the parts name mentioned earlier) in the final configure directive without modifying the Configure file
There are some options that are default, and you can also specify options. These default options are not a problem in most cases, but if your program is to be deployed to some of the uncertain Linux systems, such as some systems that don't even have jpg,png libraries (these are the system libraries used in the Configure default option, it's tragic if the system doesn't have those libraries), Then you can add several options to –qt-gif-qt-libpng–qt-libmng–qt-libjpeg.
If you decide to use only static libraries for the final product release, then you don't need to compile the debug library, just compile release.
4. Generate Makefile Using Configure
Because you not only want to use your own compiled static library, you also want to be able to use the SDK automatically installed dynamic libraries and those demos,examples, in order to allow the two QT libraries to coexist, configure must be a static library with a different location of the dynamic Library folder, such as my SDK installed to/ opt/qtsdk-2010.05/, then I set up under/opt a folder called Qtstatic to hold the static library, and then use the Configure command:
./configure–prefix/opt/qtstatic–static–release. Of course, I don't like to see the full-screen mess of the output, and because a small error suddenly terminated the compilation, so the following options are specified:
-continue When an error occurs, continue compiling as far as possible
-silent only displays warnings and errors when making a make, and does not output compilation instructions to the screen
Of course, if you did not modify the Configure file in the first way to prune the compilation module, do not forget to add the-nomake option, such as you do not want to compile examples, you can add:
-nomake examples, in turn
Because the project is relatively large, this step may take a few minutes. If you specify that the content of the compilation is not many, it should be done quickly.
5. Compiling and installing
In the end, it's made and make install, but don't forget the multi-threaded build feature! If your machine is not going to do anything else this time, you can simply add the following options:
-K to continue compiling as possible when an error occurs
-j N compiles at the same time, it is recommended that the value of n is your CPU core number X1.5. Of course, I picked a slightly harsh value, my computer is the Pentium Dual-core t4300,make instruction is: make–k–j 4, then I saw the System Monitor CPU directly to 100%.
The build is complete, and make install is ready. Of course, as a Linux system, you need to pay attention to folder permissions issues ... Well, if you don't understand the problem, I think you need to do a little bit more on Linux.
6. How to statically compile a program
In the pro file, add
CONFIG +=static or
CONFIG +=staticlib, depending on your project type.
This allows the compiler to try to find a static library to connect to (including those outside the Qt Library), which, of course, does not preclude QT from statically connecting to some libraries that cause compatibility issues. A solution has been proposed in QT centre and can be consulted if necessary:
Http://www.qtcentre.org/wiki/index.php?title=Building_static_applications
7. Dynamic/Static Two-version coexistence issues
Typically, you do not need to add the location of the QT library to the system variables. QT Creator can automatically scan to the version of the QT library that exists in the system, and if not, you can add the path to the static library through the creator Tool->options->qt4. While Qdevelop is not so smart, you can manually specify the location of include and Lib. Perhaps this is not a problem at all. If you miss a dynamic library, or if you don't want to experience the speed at which a snail crawls at a static compilation before the product is released, you can specify Config + = Shared in the pro file, and remember to select the appropriate version in project.
8. The problem of too large static version
First, statically compiled QT program A debug version of the program about 150M, a release version of 10M or so, so you know why I will not compile static debug library it? Because there is no need. You can use tools like STRIP,UPX (Windows) to compress the huge programs you generate. Space and speed has always been a pair of enemies, Windows statically compiled programs, after UPX compression can be reduced to the original general volume, but the start speed is also serious decline. Of course, on the program start speed, their own design and implementation is the key, the final release of the program to do not compress, it needs to be based on the actual situation.
Wish you a pleasant stay with QT!
PS. Configure phase appears "Basic XLIB functionality test Failed" Workaround:
Compiling qt-x11-opensource-src-4.5.3 is the "Basic XLIB functionality test Failed" appears
Workaround:
This complete error message is in the./configure phase
Basic XLIB functionality Test failed!
You might need to modify the Include and library search paths by editing
Qmake_incdir_x11 and Qmake_libdir_x11 in/home/zhu/qt/qt-x11-opensource-src-4.5.2/mkspecs/linux-g++
Enter Config.test/x11/xlib execute make command to see error message
g++-wl,-o1-o Xlib XLIB.O-L/USR/X11R6/LIB-LXEXT-LX11-LM
/usr/bin/ld:cannot Find-lxext
Can see, g++ under/usr/x11r6/lib, can't find libxext.so
The reason is the need to install LIBX11 development package, according to their own system characteristics, installation Libx11-dev Libxext-dev Libxtst-dev
For Ubuntu, direct sudo apt-get install Libx11-dev libxext-dev Libxtst-dev
Problem Solving!
Reference: http://www.linuxidc.com/Linux/2011-05/36303.htm
Fast static compilation of QT and QT dynamic/static version coexistence under Linux