Share via


MSBuild error MSB8041

MSB8041: MFC/ATL Libraries are required for this project.

This error occurs when MFC or ATL is required for a build, but it wasn't found.

Remarks

MFC and ATL libraries aren't installed by default when you install a C++ workload in Visual Studio. To fix the error, make sure the right versions of MFC and ATL libraries for your build toolset are installed. There are versions of MFC for each version of the C++ build tools, for each target platform, and with or without Spectre mitigations. For example, C++ MFC for latest v143 build tools (x86 and x64) has the x86 and x64 libraries without Spectre mitigations for the latest version of Visual Studio 2022 (v143). If you simply want to use the latest libraries for a given version of a Visual Studio toolset, you need C++ MFC for latest [version] build tools ([target]) for non-Spectre builds and C++ MFC for latest [version] build tools with Spectre Mitigations ([target]) for Spectre mitigated builds. Choose the correct option for your target platform architecture. The others are for cases where you're specifically targeting an earlier toolset. For more information, see MFC Library Versions.

To install the MFC and ATL libraries

  1. Open the Visual Studio Installer.
  2. Choose the Modify button next to the version of Visual Studio you use.
  3. Select the Individual components tab at the top of the dialog box.
  4. Enter MFC in the Search components box.
  5. Select the MFC components that match your project targets, such as x86 or ARM64EC. Select the components with Spectre mitigations if you build your projects with Spectre mitigations enabled.
    • In most cases, you want to select MFC for the latest build tools. Your organization or project may require a specific, earlier version of the toolset. Make sure the version, targets, and Spectre mitigations of the MFC components you install match the toolset version, targets, and Spectre mitigations required by the project you're building.
  6. Enter ATL in the Search components box.
  7. Select the ATL components that match your project targets, such as x86 or ARM64EC. Select the components with Spectre mitigations if you build your projects with Spectre mitigations enabled.
    • In most cases, you want to select ATL for the latest build tools. Your organization or project may require a specific, earlier version of the toolset. Make sure the version, targets, and Spectre mitigations of the ATL components you install match the toolset version, targets, and Spectre mitigations required by the project you're building.
  8. Choose Modify to install the selected components.

For more information about modifying Visual Studio to install the libraries and binaries you need, see Modify Visual Studio.

Advanced diagnostics

For detailed build troubleshooting, this error is triggered in the C++ build process in the MSBuild target Microsoft.CppBuild.targets when the following file isn't found: $(VCToolsInstallDir)atlmfc\lib\$(_SpectreLibsDir)$(PlatformShortName)\mfcs140.lib. The properties come from the environment ($(VCToolsInstallDir)) and the project configuration: $(_SpectreLibsDir) is empty or spectre\, $(PlatformShortName) is x86, x64, arm, arm64, or arm64EC.