Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use 64 bit compiler in Visual Studio

I use Visual Studio 2017. In a project (that I target as x64), I get error : C1060, compiler is out of heap space, and sadly learned there happen to exist a memory limitation for compilation.

When monitoring CL.exe, it indeed stop just before reaching 4GB. So it looks like CL.exe is by default a 32bits application, as seen at : https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line

After reading this page, I installed "Universal Windows Platform workload" hoping to get access to a 64 bit version of CL.exe. But no change when compiling my project, and I can't see a single option in visual studio to choose compiler version.

I assume that there must exist a workaround to be able to use more than 4GB for a single compilation unit, but I couldn't find it for now. Any help would be much appreciated.

Edit : I hit limitation in Debug mode. Compilation is doing fine in Release mode. Which is suppose makes sense.

like image 997
brahmin Avatar asked Oct 11 '17 08:10

brahmin


People also ask

Is there a Visual Studio 64-bit?

Visual Studio 2022 on Windows is now a 64-bit application.

How do I run a compiler in Visual Studio?

Build and run your code in Visual Studio To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process. To run the code, on the menu bar, choose Debug, Start without debugging. A console window opens and then runs your app.

How do I change from platform target to x64?

To enable x64 as a CPU platform targetClick Configuration Manager. In the Configuration Manager dialog, open the Active solution platform drop-down list box and click <New> …. In the New Solution Platform dialog, select x64 in the Type or select the new platform drop-down list box.


1 Answers

By default Visual Studio uses the 32-bit toolchain (i.e. the compiler is 32-bit and cross-compiles 64-bit executables). Visual Studio 2015 and 2017 include both 32-bit and 64-bit versions of all the compilers (x86, x64, arm, arm64).

You can opt-in to using the 64-bit toolchain on a 64-bit system by two methods:

  1. Add a environment variable on your build machine (either system-wide or from a VS Developer Command Prompt).

For example:

set PreferredToolArchitecture=x64
devenv
  1. You can edit your vcxproj files to do this as well with the <PreferredToolArchitecture>x64</PreferredToolArchitecture> element:

For example:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <PreferredToolArchitecture>x64</PreferredToolArchitecture>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>

I use the second method in the UWP (C++/WinRT) versions of my Direct3D Game VS Templates, and I just noticed that I should add it to my UWP (C++/CX) and Win32 versions. The Xbox One XDK automatically does this in it's platform build rules as well.

Note this question has been answered in the past: How to make Visual Studio use the native amd64 toolchain

like image 146
Chuck Walbourn Avatar answered Sep 28 '22 07:09

Chuck Walbourn