在 Visual Studio 中使用 64 位编译器

Use 64 bit compiler in Visual Studio

我使用 Visual Studio 2017。在一个项目(我的目标是 x64)中,我得到错误:C1060,编译器超出堆 space,遗憾的是得知恰好存在一个编译的内存限制。

监控CL.exe的时候,确实快到4GB就停止了。所以它看起来像 CL.exe 默认情况下是一个 32 位应用程序,如所见:https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line

阅读此页后,我安装了 "Universal Windows Platform workload",希望能够访问 CL.exe 的 64 位版本。但是编译我的项目时没有变化,我在 visual studio 中看不到一个选项来选择编译器版本。

我认为必须存在一种解决方法才能为单个编译单元使用超过 4GB 的内存,但我暂时找不到。任何帮助将不胜感激。

编辑:我在调试模式下遇到了限制。编译在发布模式下运行良好。假设是有道理的。

默认情况下 Visual Studio 使用 32 位工具链(即编译器是 32 位并交叉编译 64 位可执行文件)。 Visual Studio 2015 和 2017 包括所有编译器(x86、x64、arm、arm64)的 32 位和 64 位版本。

您可以通过两种方法选择在 64 位系统上使用 64 位工具链:

  1. 在您的构建机器上添加一个环境变量(在系统范围内或从 VS 开发人员命令提示符)。

例如:

set PreferredToolArchitecture=x64
devenv
  1. 您也可以编辑 vcxproj 文件以使用 <PreferredToolArchitecture>x64</PreferredToolArchitecture> 元素执行此操作:

例如:

<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>

我在 Direct3D Game VS Templates 的 UWP (C++/WinRT) 版本中使用第二种方法,我只是注意到我应该将它添加到我的 UWP (C++/CX) 和 Win32 版本中。 Xbox One XDK 也在其平台构建规则中自动执行此操作。

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