CppPilot

Linker diagnostic Visual Studio C++

LNK4098 defaultlib conflicts with use of other libs

The object files and libraries of the program were compiled with different C runtime libraries, such as /MD and /MT, or Debug and Release. The program may crash when memory or objects cross between them.

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
warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

Causes & corrections

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

  1. A library uses another runtime library.

    Build all projects and libraries with the same C/C++ > Code Generation > Runtime Library: /MD with /MDd in Debug, or /MT with /MTd. Use the library build that matches.

    Problem

    App: /MDVendor library: /MT

    Correction

    App: /MDVendor library: matching /MD build
    Note 1Use compatible runtime variants instead of default-library suppression.
  2. A Release library is linked in Debug.

    Link the Debug build of the library in the Debug configuration.

    Problem

    App: Debug (/MDd)Core: Release (/MD)

    Correction

    App: Debug (/MDd)Core: Debug (/MDd)
    Note 2Keep Debug dependencies separate from Release dependencies.
  3. /NODEFAULTLIB hides the conflict.

    Ignoring the default library silences the warning without making the runtimes compatible: use it only for a library you know is not needed.

    Problem

    Mixed /MD and /MT objectsAdditional Options: /NODEFAULTLIB:MSVCRT

    Correction

    Rebuild or replace mismatched objectsUse compatible runtime settingsRemove the suppression hiding this mismatch
    Note 3Suppressing a library does not make incompatible runtime ownership safe.

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