在 Visual Studio 中使用 64 位编译器
我使用 Visual Studio 2017.在一个项目中(我的目标是 x64),我收到错误:C1060,编译器堆空间不足,遗憾的是,编译时碰巧存在内存限制.
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.
在监控 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
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
阅读此页面后,我安装了通用 Windows 平台工作负载",希望能够访问 64 位版本的 CL.exe.但是在编译我的项目时没有任何变化,而且我在 Visual Studio 中看不到一个选项来选择编译器版本.
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.
我认为必须存在一种解决方法才能为单个编译单元使用超过 4GB 的空间,但我现在找不到它.任何帮助将不胜感激.
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.
推荐答案
默认情况下,Visual Studio 使用 32 位工具链(即编译器是 32 位并交叉编译 64 位可执行文件).Visual Studio 2015 和 2017 包括所有编译器(x86、x64、arm、arm64)的 32 位和 64 位版本.
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).
您可以通过两种方法选择在 64 位系统上使用 64 位工具链:
You can opt-in to using the 64-bit toolchain on a 64-bit system by two methods:
- 在您的构建机器上添加环境变量(系统范围或来自 VS 开发人员命令提示符).
例如:
set PreferredToolArchitecture=x64
devenv
- 您也可以使用
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
元素编辑您的vcxproj
文件:
- You can edit your
vcxproj
files to do this as well with the<PreferredToolArchitecture>x64</PreferredToolArchitecture>
element:
例如:
<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 游戏 VS 模板的 UWP (C++/WinRT) 版本中使用第二种方法,我刚刚注意到我应该将它添加到我的 UWP (C++/CX) 和 Win32 版本中.Xbox One XDK 也会在其平台构建规则中自动执行此操作.
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.
请注意,过去已回答过此问题:如何让Visual Studio使用原生的amd64工具链
Note this question has been answered in the past: How to make Visual Studio use the native amd64 toolchain
相关文章