CppPilot

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.

Applies toMSVC on Windows; code and debugger concepts apply to MSBuild and CMake
ExamplesFocused excerpts; required context is stated alongside each example

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.

Build output
error LNK2026: module unsafe for SAFESEH image.

Causes & corrections

Find the case that matches your build. Each example shows what changes and why.

  1. 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 metadata

    Correction

    Rebuild Legacy.lib for Win32Use a toolset and objects compatible with /SAFESEH
    Note 1Prefer a compatible library build to disabling the protection.
  2. 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.asm

    Correction

    MASM > Advanced > Use Safe Exception HandlersYes (/safeseh)Declare applicable handlers with .SAFESEH
    Note 2Mark actual assembly exception handlers as required; /safeseh alone cannot repair arbitrary old objects.
  3. 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 LNK2026

    Correction

    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