Accelerate QT Engineering compilation speed (also available to Qt for Android settings)

Source: Internet
Author: User

One, multi-core compilation

Environment: WIN10, Qt 5.4.1, compiler mingw32

Project: Qt for Android

Qt Creator does not support precompilation when compiling Android projects, the default CPU single-core compilation, the project is slightly larger, resulting in a very slow compilation process, affecting efficiency.

However, Qt creator comes with a multi-core compiler tool support, but does not turn on by default and requires its own configuration in the project to take effect.

The steps are "take this machine and project as an example":

1. See if the Jom tool is already installed: C:\Qt\Qt5.4.1\Tools\QtCreator\bin\jom.exe

2. Project Add parameter-j 4 "4 is the CPU's core number, mine is i5, only four cores"

After you have added the parameters, you can recompile the project try, compile the task Manager can be opened, you can see all the CPU core can be fully utilized.

Before my machine "CPU i5-4590/memory 8g/HDD" Project all re-compiled takes more than 50 minutes, after enabling multicore, it only takes about 13 minutes.

PS. If the compiler is the MS VC + +, you only need to add qmake_cxxflags + =/MP in the. Pro file.

Second, use the precompiled header

It is wrong to say that the program compiled with QT is slower than MFC. Unit code number of lines compiled QT is much faster than MFC, because the QT library header file design is very good, as far as possible to use the pre-declaration, avoid the header file nesting, almost all classes use the public class and private class design, put unnecessary public declarations into the private header file, avoid the introduction of excessive code at compile time. and MFC does not have such a design.
As for everyone feel MFC fast main reason is MFC project by default open the compilation preprocessing header file (PCH), but this is the characteristics of the VC compiler, all C + + programs can be used, not MFC-specific, QT can also use PCH.
Method is simple, add a row to your. Pro file

Precompiled_header = stable.h

Specify Stable.h this header file as a compilation preprocessing file, MFC This file is generally called stdafx.h. Then include all the QT header files you use in the stable.h, and if you use a lot of QT classes you can directly include all
Like what:

#include <QtCore>
#include <QtGui>

These two files contain almost all of the QT common classes. Don't worry, even if all the header files are included, it doesn't matter if you have a PCH and a long file.
If you still want to compile faster, you can add the following line to the. Pro

Qmake_cxxflags + =/MP

Specifying the/MP compilation option, the compiler will use parallel compilation and compile different CPP concurrently with multiple compilation processes
And Qt This method of introducing PCH is better than MFC, because MFC's PCH option is specified per project, it is easy to be bad for some people, I have fixed the PCH problem countless times, but the QT option is written in the. Pro, write once will never be wrong.
Once the MFC has broken the PCH, the compilation is also very slow.

Original link: http://blog.csdn.net/hsshh1988/article/details/52604196

Original link: http://blog.csdn.net/crlyn/article/details/52005606

http://blog.csdn.net/caoshangpa/article/details/75204018

Accelerate QT Engineering compilation speed (also available to Qt for Android settings)

Related Article

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.