[Conversion] QT 4.8 static library Compilation Method

Source: Internet
Author: User

The first step on QT was directed by xiaomagee. Compared with conventional window program development, QT has the following features:

1. Excellent cross-platform features (support for Windows, Linux, and Mac platforms only need to be re-compiled)

2. Object-oriented

3. Rich APIs

4. Supports 2D/3D graphic rendering and OpenGL

5. A large number of development documents (no need to install several g msdn like Vc)

6. XML support

In fact, the first point is enough for me to switch from VC to QT. In addition, I found in my learning process that QT can easily create a beautiful interface, which makes me easy to understand. QT is a good choice whether it is to create some small utility programs or develop a host computer!

Previously, when using VC ++, only compiled EXE files can be run on most computers. However, QT is different because QT is dynamically compiled by default, for normal operation, you need to call the standard library of QT (that is. DLL), so if you want to run it independently from the IDE, you must include the associated dllw.exe in the same directory (or in the System32 folder), or add the path of the QT standard library to the environment variable. Otherwise, the following warning will appear:

This limits the universality of QT, especially when using QT to develop a host computer, if you need to observe data on a computer, in addition to EXE, You have to copy a lot of DLL in the past, it seems very troublesome. Is there any way to satisfy this problem? You only need an EXE file to run it on all the computers with Windows installed? The answer is yes!

This requires static compilation of the standard library of QT.

I have searched for a large amount of information on the Internet. After various attempts and various failures, I finally completed the library compilation of the latest version of qt4.8. Now we will organize the entire process from software installation for your reference and communication.

PS: the qt sdk in Windows is used as the development environment. If vs is used for compilation, you only need to make slight modifications in some steps. I don't need vs for a long time, so I did not test it myself.

Step 1: download the software installation package

The following three installation packages are required.

1. QT download

Address: http://qt.nokia.com/downloads

Download qt sdk and QT Library

Select offline installation package

Select the QT standard library for mingw (vs version check box)

Perl is required for compiling the qt4.8 standard library.

Http://www.activestate.com/activeperl/downloads

Step 2: install the software

1. Install the QT SDK

Currently, QT has been acquired by NOKIA. Therefore, there are many development components for Mobile Phone programs in the installation package. If you do not need them, follow the configurations shown below to remove unnecessary components.

Select "Custom" on this page"

Remove all APIs

In "development tools", select "QT creator" (default) and "mingw" in "desktop QT ".

Personal judgment: This library is used for dynamic QT compilation. You can choose to install it to implement it in the future: it is convenient and convenient to use the dynamic library during debugging; it is convenient to use the static library during release.

Here I chose mingw again, for the sake of insurance :)

2. Install the QT standard library

Note that the installation directory of mingw must be selected in the last step before installation. In the qtsdk folder

Select the mingw folder.

3. Install the Perl Environment

Just click Next

Step 3: Compile the standard library

1. Configure compilation options

1) Open X: \ QT \ 4.8.0 \ mkspecs \ win32-g ++ \ qmake. conf (X is the QT installation drive letter)

(Backup is recommended first)

Add-static to qmake_lflags

Change-shared after qmake_lflags_dll to-static.

Save and close

2) delete or rename the syncqt and syncqt. BAT files under X: \ QT \ 4.8.0 \ bin.

Otherwise, the Perl environment cannot be found during compilation, as shown in

2. Start Compilation

Open the QT 4.8.0 command prompt software and enter

Configure-static-release-no-Exceptions

PS: This configuration only compiles the release version. If you need both the debug version of the static version, you need to change-release to-debug-and-release.

Press enter to select the version and user protocol. Press "O" (Open Source) "Y" (yes)

............ Wait patiently ............

The following figure is displayed after the configuration is complete:

---- Make sure that you have at least two hours of free time before you start this step ----

Then enter the mingw32-make sub-Src

Enter ......... What should I do ............ Until you see the following picture:

PS: You can browse the Web page during compilation and chat on Weibo, but it is not recommended to run large programs. Otherwise, the Compilation speed will be greatly reduced !!

When you see this picture, congratulations, It will be successful soon ~

Step 4: Configure QT creator

Open QT creator to create a project, and click the manage button shown in the project interface.

Click Add

Go to the X: \ QT \ 4.8.0 \ qmake directory and select qmake.exe, as shown in figure

The version name below can be started by myself (I use QT 4.8.0 static)

Return to the project page and add the selected compiler.

After selecting the mode, make sure that you have selected the release version of qt4.8.0 (the static debug version is not compiled, so selecting this mode will cause an error)

Compile the program and enter the project directory. Double-click the program to run the program perfectly!

So far, QT static compilation is complete.

Because the size of the EXE compiled by QT is large, you can compress it to save space and facilitate storage and propagation. UPX is used here.

Copy UPX. EXE to the c: \ windows \ system32 directory.

In cmd, enter UPX (+ space) (+ file path + file name) (+ press Enter)

You can see

The compression ratio is 39.93%. The visible effect is quite impressive.

So far, all static libraries of QT have been compiled.

To ensure the accuracy of the tutorial, I have completely deleted QT and re-installed and compiled it before writing the tutorial. I will write one step of the tutorial every step completed. My compilation method may not be the best, but according to my method, it can be successful!

 

From: http://www.uzzf.com/news/2131.html

[Conversion] QT 4.8 static library Compilation Method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.