gpt4 book ai didi

c++ - 在 Visual Studio 中使用 64 位编译器

转载 作者:可可西里 更新时间:2023-11-01 16:32:05 30 4
gpt4 key购买 nike

我使用 Visual Studio 2017。在一个项目(我的目标是 x64)中,我收到错误:C1060,编译器堆空间不足,遗憾的是得知编译时碰巧存在内存限制。

当监控 CL.exe 时,它​​确实在达到 4GB 之前停止了。所以看起来 CL.exe 默认是一个 32 位的应用程序,见:https://learn.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line

阅读此页后,我安装了“通用 Windows 平台工作负载”,希望能够访问 64 位版本的 CL.exe。但是在编译我的项目时没有任何变化,而且我在 visual studio 中看不到一个选项来选择编译器版本。

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

编辑:我在 Debug模式下遇到了限制。编译在 Release模式下运行良好。这是有道理的。

最佳答案

默认情况下,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

关于c++ - 在 Visual Studio 中使用 64 位编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46683300/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com