Linker diagnostic Visual Studio C++
LNK2026 module unsafe for SAFESEH image
In Win32 (x86) builds, the linker creates a table of safe exception handlers, and a module it links does not provide one. The error does not exist in x64 builds.
Visual Studio property-page paths describe MSBuild projects. For CMake, configure the corresponding target or preset. Menu names can vary by Visual Studio version; use the cited reference for your toolset.
error LNK2026: module unsafe for SAFESEH image.Causes & corrections
Find the case that matches your build. Each example shows what changes and why.
A library was built by an old compiler.
Rebuild the library with the current toolset, or get a recent build of it.
Problem
Win32 app: /SAFESEHLegacy.lib: old objects without SafeSEH metadataCorrection
Rebuild Legacy.lib for Win32Use a toolset and objects compatible with /SAFESEHNote 1Prefer a compatible library build to disabling the protection. An assembly file is assembled without
/safeseh.Set Microsoft Macro Assembler > Advanced > Use Safe Exception Handlers to Yes.
Problem
MASM input: handler.asmAssembler: ml /c handler.asmCorrection
MASM > Advanced > Use Safe Exception HandlersYes (/safeseh)Declare applicable handlers with .SAFESEHNote 2Mark actual assembly exception handlers as required; /safeseh alone cannot repair arbitrary old objects. The library cannot be rebuilt.
Set Linker > Advanced > Image Has Safe Exception Handlers to No (/SAFESEH:NO), for Win32 only. This removes a protection, so prefer rebuilding.
Problem
Win32 app needs an irreplaceable legacy libraryLink fails with LNK2026Correction
Win32 > Linker > AdvancedImage Has Safe Exception HandlersNo (/SAFESEH:NO)Note 3This compatibility workaround disables SafeSEH. Prefer rebuilding or replacing the library.
Sources and scope
Official references
These links document the compiler, build system, or debugger behavior discussed here. Use the version selector on Microsoft Learn for your toolset. Example blocks are focused excerpts; required headers and build settings are stated alongside them.
In your workspace
Investigate LNK2026 with CppPilot
CppPilot gives the selected AI the diagnostic, relevant code, and project settings for the active configuration. Choose Fix to request a correction, then check the result with a rebuild.
Use your own Codex or Claude account, or optional CppPilot Cloud access. Setup instructions
Visual Studio Marketplace