MSVC build errors > LNK2038
LNK2038: mismatch detected
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
Every object file records the C runtime and the iterator debug level it was compiled with. The linker refuses to mix object files and libraries that disagree, because they would use incompatible versions of the standard library.
Causes and fixes
- Projects use different runtime libraries. Set the same C/C++ > Code Generation > Runtime Library in every project of the program:
/MDeverywhere, or/MTeverywhere, with/MDdor/MTdin Debug. - A Release library is linked into a Debug build. A mismatch on
_ITERATOR_DEBUG_LEVEL(0 against 2) means that Debug and Release code are mixed: link the Debug version of the library in Debug builds. - A single file overrides the project. A
.cppfile can have its own Runtime Library setting. Remove the override in its properties so it inherits the project's. - A prebuilt third-party library uses another runtime. Use the variant built for your runtime, or rebuild it with your settings, for example with the matching vcpkg triplet.
Fix LNK2038 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: LNK2019, LNK2001. See all guides.