Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes the MSB8040 error code.
Message text
MSB8040: Spectre-mitigated libraries are required for this project.
Description
This error occurs when the project requires Spectre-mitigated libraries (C/C++ > Spectre Mitigation isn't set to Disabled), but the libraries aren't installed. For more information, see Spectre mitigations in Microsoft Foundation Classes (MFC).
Resolution
First, determine if you want to implement Spectre mitigation, and then follow the necessary steps to update your installation to address the error.
Disable Spectre mitigation
If you don't want to use Spectre mitigation, disable the option in Visual Studio. For command-line builds, confirm you're not using the /Qspectre
compiler option or its variants /Qspectre-load
and /Qspectre-load-cf
.
To disable the option in Visual Studio, follow these steps:
- In Solution Explorer, right-click the project node, and select Properties (Alt+Enter).
- In the Property Pages dialog for your project, select the Configuration Properties > C/C++ > Code Generation property page.
- Set the Spectre Mitigations property to Disabled.
- Select OK to save your changes.
Enable Spectre mitigation
If you decide to use Spectre mitigation, make sure your installation includes the correct compiler and library components with support for Spectre mitigation.
To update your installation, follow these steps:
- Open the Visual Studio Installer.
- Select the Modify button next to the version of Visual Studio you use.
- Select the Individual components tab at the top of the dialog.
- In the Search components box, enter Spectre v14.2.
- In the Compiler, build tools and runtime section, make sure the MSVC v142… Spectre-mitigated libs option is selected for all architectures the build targets.
- To use ATL or MFC, also select the libraries, such as C++ MFC for latest v142 build tools with Spectre Mitigations (or the appropriate version for your toolset) for all architectures the build targets. For more information, see Install MFC and ATL libraries.
- Select Modify to install the selected components.
Specify compiler options
If you enable Spectre mitigations, make sure you specify a /Qspectre
compiler option. For more information, see the /Qspectre compiler option.
To specify the /Qspectre
compiler option, follow these steps:
In Solution Explorer, right-click the project node, and select Properties (Alt+Enter).
In the Property Pages dialog for your project, select the Configuration Properties > C/C++ > Code Generation property page.
Set the Spectre Mitigations property to one of the following values:
- Enabled
- All loads for /Qspectre-load
- All Control Flow Loads for /Qspectre-load-cf
Select OK to save your changes.
Applies to
All versions of MSBuild