是否有更简洁的方法来处理编译器错误 C1076 和 C3859?

Is there a cleaner way to handle compiler errors C1076 and C3859?

今天我将一些库 headers 添加到我们的 precomp.h 文件中。然后我尝试在调试中重新编译并得到了这两个错误(从 boost include 产生):

error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm310' or greater

fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit

所以我通过增加内存堆大小来修复它们。没问题。

我的问题更多的是这个问题是否隐藏了另一个问题?如果我继续将库 headers 添加到 precomp.h,我最终是否需要给它更多的内存?这是程序员处理它的方式,还是会有一种“更干净”的方式来处理它?

更多信息:

/Zm 参数不会改变代码的解释方式,因此它不会隐藏代码中的问题,只是代码需要大量内存才能编译。

开关仅通知编译器它在编译期间应该计划的内存成本。在 VS 2013 中,默认的预编译头缓冲区大小为 75 MB, which is value that a complex project can reasonably exceed. In such situations, you can use /Zm to increase the limit. Alternately, you could invest significant work into reducing the complexity of your include files.

在大多数情况下,增加 /Zm 可以更好地利用开发人员的时间。

尝试使用 Visual Studio 中的 64 位平台工具集。这样做为我们解决了问题,它是 Microsoft's recommendations for how to address the C1076 error. It's also mentioned in a blog post on precompiled header compilation issues.

之一

要更改平台工具集,请打开项目的 .vcxproj 并根据 将 <PreferredToolArchitecture>x64</PreferredToolArchitecture> 添加到每个配置 属性 组(适用于 VS 2017,但适用于 2013) .