Search code examples
visual-c++linkervisual-studio-2017

Configure Visual C++ project to use the 64-bit tool set when building 32-bit executable


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?


Solution

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