Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Today I've been adding some library headers to our precomp.h file. Then I tried to recompile in debug and got those two errors (spawned from a 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

So I fixed them by increasing the memory heap size. No problem there.

My question is more about if this problem hides another one? Will I eventually have to give it more memory if I keep on adding library headers to the precomp.h? Is this the way programmers handle it, or would there be a "cleaner" way to do it?

More info:

  • Visual Studio 2013
  • c++
like image 348
Vaillancourt Avatar asked Apr 28 '15 13:04

Vaillancourt


2 Answers

Try using the 64-bit platform toolset in Visual Studio. Doing this resolved the issue for us, and it's is one of Microsoft's recommendations for how to address the C1076 error. It's also mentioned in a blog post on precompiled header compilation issues.

To change the platform toolset, open the project's .vcxproj and add <PreferredToolArchitecture>x64</PreferredToolArchitecture> to each configuration property group as per https://stackoverflow.com/a/46069460/478380 (which is for VS 2017 but applies to 2013).

like image 117
Gnat Avatar answered Oct 11 '22 02:10

Gnat


The /Zm parameter does not change anything about how the code is interpreted, so it does not hide a problem in the code, other than the fact that the code requires a lot of memory to compile.

The switch only informs the compiler about the memory costs it should plan for during compilation. In VS 2013, the default precompiled header buffer size is 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.

In most cases, it is a much better use of developers' time to increase /Zm.

like image 23
denis bider Avatar answered Oct 11 '22 02:10

denis bider