You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.9 KiB
2.9 KiB
| title | date | tags | categories |
|---|---|---|---|
| 加快Visual Studio编译速度 | 2018-01-05 12:08:32 | [visual studio cplusplus] | windows |
为Visual Studio开启多核编译支持,Visual Studio 2010及以上版本,直接可以在界面配置,而Visual Studio 2008则需要手动增加编译命令。
Build with Multiple Processes
Visual Studio并行编译选项命令为/MP,具体语法为:
/MP[processMax]
processMax 为可选参数,范围为1-65536,表示可以创建的并行进程数,如果省略该参数,默认为有效内核数,计算方法为: (8 effective processors) = (2 physical processors) x (2 cores per physical processor) x (2 effective processors per core because of hyperthreading)。
/MP选项会与下表中的选项冲突,所以如果需要开启/MP,需要关闭下表中其他选项,Visual Studio默认配置下debug模式会启用/Gm选项,需要手动关闭。
| Option or Language Feature | Description |
|---|---|
| #import preprocessor directive | Converts the types in a type library into C++ classes, and then writes those classes to a header file. |
| /E, /EP | Copies preprocessor output to the standard output (stdout). |
| /Gm | Enables an incremental rebuild. |
| /showIncludes | Writes a list of include files to the standard error (stderr). |
| /Yc | Writes a precompiled header file. |
为Visual Studio 2010开启多核并行编译
- 属性 -> 配置属性 -> C/C++ -> 常规 -> 多处理器编译,设为
是。1 - 属性 -> 配置属性 -> C/C++ -> 代码生成 -> 启用最小重新生成,设为
否。2 - 工具 -> 选项 -> 项目和解决方案 -> 生成并运行,设置
最大并行项目生成数为8(可以自定义合理值)。
为Visual Studio 2008开启多核并行编译
- 属性 -> 配置属性 -> C/C++ -> 命令行 -> 附加选项,添加
/MP。1 - 属性 -> 配置属性 -> C/C++ -> 代码生成 -> 启用最小重新生成,设为
否。2 - 工具 -> 选项 -> 项目和解决方案 -> 生成并运行,设置
最大并行项目生成数为8(可以自定义合理值)。
实例说明
以我自己的项目为例,不开启/MP选项,完整编译一次时间为48秒,开启之后完整编译一次时间为26秒。
{% asset_img before.png 不开启/MP选项 %}
{% asset_img after.png 开启/MP选项 %}