Globally set compiler flags (/Zm memory limit)
Asked Answered
V

1

6

When compiling some complicated templates, I sometimes get:

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

I know that I can go to project settings and specify e.g. /Zm500 to give the compiler more memory (more info on /Zm can be found here). It is however quite cumbersome and I would prefer setting a default limit globally. Is there any way to do it?

Alternately, is there any way to specify this particular flag using a pragma or other annotation of the source file? That way it would also be portable accross machines with potentially different settings.

I'm using Visual Studio 2008, if it also worked in Visual C++ 6.0, I wouldn't mind.

Vltava answered 17/9, 2014 at 8:22 Comment(4)
You have a very low threshold for "cumbersome", that workaround takes you 5 seconds. If it takes more then there's something very wrong with your workflow. Do the more cumbersome thing when you get this and either break up your source code file or use the 64-bit compiler. Real fixes instead of band-aids.Thermograph
@HansPassant What if the code in question is a part of a library and I need to do this every time a new project using that library is started? In my case, the code is real simple and not easy to be divided, but the compiler is not very efficient with templates.Vltava
@HansPassant It also makes sense to set it globally, when the project is divided into 300-400 smaller components which are all loaded in the same solution fileHedger
Does not matter, use Shift+Click to select multiple projects before editing the settings. Solutions that are guaranteed to not reproduce on another machine are not good solutions.Thermograph
V
7

I finally found an answer to this, here. All that is needed, is to set the CL environment variable:

CL=/Zm500

For example in Control Panel - System - Environment Variables (note that restart of the IDE is required). And all the builds will then use this setting, unless overridden by cl.exe commandline arguments.

This works for both MSVC 6.0 and Visual Studio 2008.

Vltava answered 19/9, 2014 at 14:15 Comment(1)
However, if someone knew how to annotate /Zm directly in source code, I would love to learn how, as it would be much better than global setting for all files that may not even need it.Vltava

© 2022 - 2024 — McMap. All rights reserved.