在Visual Studio中使用64位编译器 [英] Use 64 bit compiler in Visual Studio
问题描述
我使用Visual Studio2017。在一个项目(我的目标是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/zh-cn/cpp/build/how-to-enable-a-64 -bit-visual-cpp-tool-on-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
阅读此页后,我安装了 Universal Windows Platform工作负载,希望能够可以访问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:
- 在构建机器上添加环境变量(两个
例如:
set PreferredToolArchitecture=x64
devenv
- 您可以使用
< PreferredToolArchitecture> x64< / PreferredToolArchitecture>编辑<$ c $ c> 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 ++ / 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工具链
这篇关于在Visual Studio中使用64位编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!