编译系统 PCH 配置

修改 PCH Buffer size

默认是/Zm1000,就是 750M,如果编译时产生页面文件太小的错误:

1
2
3
4
c1xx: error C3859: Failed to create virtual memory for PCH
c1xx: note: the system returned code 1455: 页面文件太小,无法完成操作。
c1xx: note: please visit https://aka.ms/pch-help for more details
c1xx: fatal error C1076: compiler limit: internal heap limit reached

可以在项目的 target.cs 里添加以下代码:

1
2
3
4
5
if(Target.Platform == UnrealTargetPlatform.Win64)
{
bOverrideBuildEnvironment = true;
AdditionalCompilerArguments = "/Zm2000";
}

关闭 PCH

在 TargetRules.cs 中有 bUsePCHFilesbUseSharedPCHs两个选项,可以控制项目是否开启 PCH:

UnrealBuildTool\Configuration\TargetRules.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/// <summary>
/// Whether PCH files should be used.
/// </summary>
[CommandLine("-NoPCH", Value = "false")]
[XmlConfigFile(Category = "BuildConfiguration")]
public bool bUsePCHFiles = true;

/// <summary>
/// Enables "Shared PCHs", a feature which significantly speeds up compile times by attempting to
/// share certain PCH files between modules that UBT detects is including those PCH's header files.
/// </summary>
[CommandLine("-NoSharedPCH", Value = "false")]
[XmlConfigFile(Category = "BuildConfiguration")]
public bool bUseSharedPCHs = true;

但是为了不改动代码,也可以通过 BuildConfiguration.xml 中的设置:

1
2
C:\Users\lipengzha\AppData\Roaming\Unreal Engine\UnrealBuildTool\BuildConfiguration.xml
F:\EngineSource\UE_4.26\Engine\Saved\UnrealBuildTool\BuildConfiguration.xml

这两个路径下的均可,在 Configuration 下添加以下配置:

1
2
<bUsePCHFiles>true</bUsePCHFiles>
<bUseSharedPCHs>false</bUseSharedPCHs>