7

I am trying to enable link-time codegen (LTCG) and whole program optimization (WPO) for the build of a large Windows C++ application built with Visual Studio 2017. The 64-bit product builds fine but the codegen step of our 32-bit build runs out of memory.

So, I need to switch the 32-bit builds to use the 64-bit link.exe as described here: How to: Enable a 64-Bit, x64 hosted Visual C++ toolset on the command line

Specifically:

The 32-bit and 64-bit tools generate identical code, but the 64-bit tools support more memory for precompiled header symbols and the Whole Program Optimization (/GL and /LTCG) options. If you run into memory limits when you use the 32-bit tools, try the 64-bit tools.

It describes doing this from a command line build but I need it within the devenv environment. I have searched unsuccessfully for a Solution or Project setting to control using the 64-bit tool set for a 32-bit build.

I suspect I'll need to edit the .vcxproj file directly but am not sure what to add. Can anyone tell me how to setup my 32-bit build this way?

2 Answers 2

5

An alternative answer is to use PreferredToolArchitecture in the project.

Using Visual Studio 2019 (v16.1) this can be done in the properties dialog of the project under "Configuration Properties\Advanced\Prefered Build Tool Architecture". Specify x64.

For older versions of Visual Studio, editing the vcxproj is required. This is documented in Walkthrough: Using MSBuild to Create a Visual C++ Project

<PropertyGroup>
    <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
2
  • 1
    Marking this as the accepted answer as MS has finally given us a nice way and future visitors should know about it.
    – jschroedl
    Commented Mar 5, 2021 at 17:40
  • Thanks! Your answer was definitely a sign post that helped me find the newer way of doing it.
    – Steve
    Commented Mar 9, 2021 at 16:03
4

Found my own answer... You do need to hand-edit the .vcxproj file and add this to the PropertyGoup

<UseNativeEnvironment>true</UseNativeEnvironment>

So mine now looks like this:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
   <UseDebugLibraries>false</UseDebugLibraries>
   <UseOfMfc>Dynamic</UseOfMfc>
   <CharacterSet>Unicode</CharacterSet>
   <PlatformToolset>v141</PlatformToolset>
   <WholeProgramOptimization>true</WholeProgramOptimization>
   <UseNativeEnvironment>true</UseNativeEnvironment>
</PropertyGroup>
1
  • 1
    In Visual Studio 2022, UseNativeEnvironment and _IsNativeEnvironment despite their names, use the x64 toolset on Arm64 hosts. When considering Arm64 hosts it will be best to set nothing at all. Commented Mar 29 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.