Qt 预编译头文件(precompiled headers) 加快编译速度
预编译头文件:
precompiled headers, 将不经常改动的代码编译成二进制文件, 在之后每次编译的时候可会直接调用这些预编译头文件的二进制文件, 实现加快编译速度.
简单点说就是: 可以把不常更改的头文件, 通过预编译头文件的方式进行一次编译, 提高之后的编译速度. 就是为了加快编译速度, 就是为了加快编译速度, 就是为了加快编译速度!
1. Qt支持的平台
qmake 支持的预编译头(precompiled headers)的编译器包括:
- Windows
nmake
Visual Studio projects (VS 2008 and later)
- OS X and iOS
Makefile
Xcode
- Unix
GCC 3.4 and above
2. 具体使用
非常简单, 官方有介绍.
2.1 先写一个stable.h
这个
stable.h里面包含的就是需要预编译的头文件
// Add C includes here
#if defined __cplusplus
// Add C++ includes here
#include <stdlib>
#include <iostream>
#include <vector>
#include <QApplication> // Qt includes
#include <QPushButton>
#include <QDebug>
#include "thirdparty/include/libmain.h"//第三方类
#include "my_stable_class.h"//自己的稳定类
...
#endif
2.2 工程配置文件.pro中添加
PRECOMPILED_HEADER = stable.h
就这两步就可以了! 这样就可以缩短编译时间了!
3 实例应用:解决中文乱码
解决windows下vc++ 12编译器qDebug()等中文乱码问题
在stable.h中添加
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif