8

I have a C++ project with a lot of templates and it fails to compile with fatal error C1060: compiler is out of heap space. There's plenty of free RAM. I tried paying with /Zm compiler option, but it didn't help. I can see that Visual Studio uses the 32 bit version of the compiler and I think this is the reason for this error. Is there any way to force Visual Studio to use 64 bit compiler instead?

UPDATE

My question is not a duplicate. I saw the other questions and tried the suggestions. But in my case the compiler takes more than 6 GB of RAM to compile the project. It was the maximal amount of RAM allocated by the 64 bit compiler. I can use the 64 bit compiler when building my project using msbuild, but I want to build it from Visual Studio and it's using 32 bit compiler by default. I want to force it to use the 64 bit compiler. By 64 bit compiler I mean the compiler that not only creates a 64 bit applications, but which is a 64 bit application itself.

Max
  • 19,654
  • 13
  • 84
  • 122
  • Look this question and try @Colin Robertson's comment – RomCoo Apr 25 '16 at 16:55
  • 1
    did you try this? https://msdn.microsoft.com/en-us/library/yz7kx3y2.aspx – phuclv Apr 25 '16 at 16:56
  • 2
    Possible duplicate of [How to work around Visual Studio Compiler crashes](http://stackoverflow.com/questions/1388608/how-to-work-around-visual-studio-compiler-crashes) – phuclv Apr 25 '16 at 16:57
  • Switching the IDE to use a 64-bit compiler is rocket science. You might get somewhere with $(VC_ExecutablePath_x64_x86);$(VC_ExecutablePath_x64_x64);$(WindowsSDK_ExecutablePath_x64);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\System32;$(FxCopDir);$(PATH) – Hans Passant Apr 25 '16 at 18:17
  • @Lưu Vĩnh Phúc, Yes, I tried these. – Max Apr 25 '16 at 18:39
  • @Lưu Vĩnh Phúc, I searched SO before posting and tried suggested things. The problem is that the compiler needs more memory than a 32 bit process can aquire. This is why I want to switch to a 64 bit compiler. – Max Apr 25 '16 at 18:41
  • @Hans Passant, Thank you! That seems to be a step in the right direction. I can see that Visual Studio is using a 64 bit version of `cl.exe`. But unfortunately I get a new error from the linker: ` fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'`. I looks like at some point the compiler is trying to build a x86 target. But I'm trying to build a 64 bit target. – Max Apr 25 '16 at 20:12
  • $(VC_ExecutablePath_x64_x64);$(WindowsSDK_ExecutablePath_x64);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(FxCopDir);$(PATH). Delete the .pch file by hand. – Hans Passant Apr 25 '16 at 20:19
  • @Hans Passant, Thank you, that worked. Could you make your comment an answer, so I can accept it? – Max Apr 25 '16 at 21:33
  • Just write it up yourself and accept the post to close your question. – Hans Passant Apr 25 '16 at 22:00

2 Answers2

1

Referring to https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx?f=255&mspperror=-2147217396#Anchor_1, compiler which is x64 64-bit native can be used.

To do so, as mentioned on https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx#Anchor_0, run vcvarsall amd64 on command prompt.

Then, when running devenv on command line, add the /useenv option :

If you are using DEVENV for command-line builds, the environment set by vcvarsall.bat or vcvars32.bat does not affect your builds, unless you also specify the /useenv option.

Brice
  • 89
  • 1
  • 5
1

As suggested by Hans Passant in the comments the solution to this problem was to change the Executable Directories with the one's that point to the 64-bit binaries.

To do this you need to go to C++ project properties → VC++ Directories → Executable Directories in Visual Studio and replace the value with

$(VC_ExecutablePath_x64_x64);$(WindowsSDK_ExecutablePath_x64);$(VS_ExecutablePat‌​h);$(MSBuild_ExecutablePath);$(FxCopDir);$(PATH)

This change forces Visual Studio to use 64-bit C++ compiler.

Max
  • 19,654
  • 13
  • 84
  • 122