Mismatch Detected for 'RuntimeLibrary'

mismatch detected for 'runtimelibrary
lnk2038 mismatch detected for '_msc_ver'
mismatch detected for 'runtimelibrary' value 'md_dynamicrelease'
_iterator_debug_level visual studio 2017
c++ mismatch detected for
failifmismatch mismatch detected for _iterator_debug_level
cmake _iterator_debug_level
lnk20138

I downloaded and extracted Crypto++ in C:\cryptopp. I used Visual Studio Express 2012 to build all the projects inside (as instructed in readme), and everything was built successfully. Then I made a test project in some other folder and added cryptolib as a dependency. After that, I added the include path so I can easily include all the headers. When I tried to compile, I got an error about unresolved symbols.

To remedy that, I added C:\cryptopp\Win32\Output\Debug\cryptlib.lib to link additional dependencies. Now I get this error:

Error   1   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(cryptlib.obj)    CryptoTest
Error   2   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(iterhash.obj)    CryptoTest
Error   3   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(sha.obj) CryptoTest
Error   4   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(pch.obj) CryptoTest
Error   5   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(misc.obj)    CryptoTest
Error   6   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(queue.obj)   CryptoTest
Error   7   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(algparam.obj)    CryptoTest
Error   8   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(filters.obj) CryptoTest
Error   9   error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(fips140.obj) CryptoTest
Error   10  error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(cpu.obj) CryptoTest
Error   11  error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in program.obj    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\cryptlib.lib(mqueue.obj)  CryptoTest

I also get:

Error   12  error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12@std@@QAE@XZ) already defined in cryptlib.lib(cryptlib.obj)    C:\Data\Work\C++ VS\CryptoTest\CryptoTest\msvcprtd.lib(MSVCP110D.dll)   CryptoTest
Error   13  error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in cryptlib.lib(cryptlib.obj)   C:\Data\Work\C++ VS\CryptoTest\CryptoTest\msvcprtd.lib(MSVCP110D.dll)   CryptoTest
Error   14  error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ) already defined in cryptlib.lib(cryptlib.obj)   C:\Data\Work\C++ VS\CryptoTest\CryptoTest\msvcprtd.lib(MSVCP110D.dll)   CryptoTest
Error   15  error LNK2005: "public: __thiscall std::locale::id::id(unsigned int)" (??0id@locale@std@@QAE@I@Z) already defined in cryptlib.lib(iterhash.obj) C:\Data\Work\C++ VS\CryptoTest\CryptoTest\msvcprtd.lib(MSVCP110D.dll)   CryptoTest
Warning 16  warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library   C:\Data\Work\C++ VS\CryptoTest\CryptoTest\LINK  CryptoTest
Error   17  error LNK1169: one or more multiply defined symbols found   C:\Data\Work\C++ VS\CryptoTest\Debug\CryptoTest.exe 1   1   CryptoTest

The code I tried to compile was simple (I got this from another site):

#include <iostream>
#include <string>
#include "sha.h"
#include "hex.h"
using namespace std;

string SHA256(string data) {
    byte const* pbData = (byte*) data.data();
    unsigned int nDataLen = data.size();
    byte abDigest[32];

    CryptoPP::SHA256().CalculateDigest(abDigest, pbData, nDataLen);

    return string((char*)abDigest);
}

int main(void) {

    return 0;
}

Any ideas how to fix this? I really only need SHA-256 right now, nothing else. I am using Windows 7 64 bit, and I downloaded VS C++ today, so it should be the newest version.

(This is already answered in comments, but since it lacks an actual answer, I'm writing this.)

This problem arises in newer versions of Visual C++ (the older versions usually just silently linked the program and it would crash and burn at run time.) It means that some of the libraries you are linking with your program (or even some of the source files inside your program itself) are using different versions of the CRT (the C RunTime library.)

To correct this error, you need to go into your Project Properties (and/or those of the libraries you are using,) then into C/C++, then Code Generation, and check the value of Runtime Library; this should be exactly the same for all the files and libraries you are linking together. (The rules are a little more relaxed for linking with DLLs, but I'm not going to go into the "why" and into more details here.)

There are currently four options for this setting:

  1. Multithreaded Debug
  2. Multithreaded Debug DLL
  3. Multithreaded Release
  4. Multithreaded Release DLL

Your particular problem seems to stem from you linking a library built with "Multithreaded Debug" (i.e. static multithreaded debug CRT) against a program that is being built using the "Multithreaded Debug DLL" setting (i.e. dynamic multithreaded debug CRT.) You should change this setting either in the library, or in your program. For now, I suggest changing this in your program.

Note that since Visual Studio projects use different sets of project settings for debug and release builds (and 32/64-bit builds) you should make sure the settings match in all of these project configurations.

For (some) more information, you can see these (linked from a comment above):

  1. Linker Tools Warning LNK4098 on MSDN
  2. /MD, /ML, /MT, /LD (Use Run-Time Library) on MSDN
  3. Build errors with VC11 Beta - mixing MTd libs with MDd exes fail to link on Bugzilla@Mozilla

UPDATE: (This is in response to a comment that asks for the reason that this much care must be taken.)

If two pieces of code that we are linking together are themselves linking against and using the standard library, then the standard library must be the same for both of them, unless great care is taken about how our two code pieces interact and pass around data. Generally, I would say that for almost all situations just use the exact same version of the standard library runtime (regarding debug/release, threads, and obviously the version of Visual C++, among other things like iterator debugging, etc.)

The most important part of the problem is this: having the same idea about the size of objects on either side of a function call.

Consider for example that the above two pieces of code are called A and B. A is compiled against one version of the standard library, and B against another. In A's view, some random object that a standard function returns to it (e.g. a block of memory or an iterator or a FILE object or whatever) has some specific size and layout (remember that structure layout is determined and fixed at compile time in C/C++.) For any of several reasons, B's idea of the size/layout of the same objects is different (it can be because of additional debug information, natural evolution of data structures over time, etc.)

Now, if A calls the standard library and gets an object back, then passes that object to B, and B touches that object in any way, chances are that B will mess that object up (e.g. write the wrong field, or past the end of it, etc.)

The above isn't the only kind of problems that can happen. Internal global or static objects in the standard library can cause problems too. And there are more obscure classes of problems as well.

All this gets weirder in some aspects when using DLLs (dynamic runtime library) instead of libs (static runtime library.)

This situation can apply to any library used by two pieces of code that work together, but the standard library gets used by most (if not almost all) programs, and that increases the chances of clash.

What I've described is obviously a watered down and simplified version of the actual mess that awaits you if you mix library versions. I hope that it gives you an idea of why you shouldn't do it!

error LNK2038: mismatch detected for , Trying to build your Poco example. PocoFoundationmdd.lib(Clock.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL':� detect_mismatch pragma. 08/29/2019; 2 minutes to read +2; In this article. Places a record in an object. The linker checks these records for potential mismatches.

LNK2038 mismatch detected for _ITERATOR_DEBUG_LEVEL , lib(RuntimeInstance.obj) : error LNK2038: mismatch detected for '_ ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in corert-demo. HWC2008: A fabric mismatch detected for mezzanine card C. Detailed Description: The fabric type for the IOM and mezzanine cards must match. Once an IOM or mezzanine card is inserted into the chassis, the fabric type is then set for the CMC and the CMC will ensure that all subsequent IOM's and mezzanine cards match. Recommended Action:

I had this problem along with mismatch in ITERATOR_DEBUG_LEVEL. As a sunday-evening problem after all seemed ok and good to go, I was put out for some time. Working in de VS2017 IDE (Solution Explorer) I had recently added/copied a sourcefile reference to my project (ctrl-drag) from another project. Looking into properties->C/C++/Preprocessor - at source file level, not project level - I noticed that in a Release configuration _DEBUG was specified instead of NDEBUG for this source file. Which was all the change needed to get rid of the problem.

mismatch detected for '_ITERATOR_DEBUG_LEVEL , Hi,. I saw a lot of posts regarding this issue, but still I have a problem. I imported a working solution to Visual Studio 2010. When I compile i� Intallation error: Version mismatch detected. Just getting started. floripare. 26 October 2019 14:39 #1. I had to uninstall Postman on a Windows 10 Pro 64-bit machine

Issue can be solved by adding CRT of msvcrtd.lib in the linker library. Because cryptlib.lib used CRT version of debug.

Cisco Catalyst 6500/6000 Series Switches, MATLAB coder compiled C++ library error LNK2038: mismatch detected for ' _ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in� Re: WARNING: CRC mismatch detected Mon Jul 20, 2015 3:01 pm I haven't had CRC mismatch errors.. but I have had alot more communication issues with my Wanhao D4 than i did with 2.2 usually only resolve is to close S3D and turn off the printer then launch S3D and turn the printer back on.. usually have to do this 2-3 times before im able to print.

Single-mismatch detection using gold-quenched fluorescent , %CDP-4-NVLANMISMATCH: Native vlan mismatch detected on port [dec]/[dec] This message indicates that the native VLAN is different from the one set on at� In VS2010 iterator debug level defaults to 2 in debug and is disabled in release. One of the dlls you are using probably has iterator debugging turned off in debug either because it was built in an older version of visual studio or they explicitly added the defines to the project.

error LNK2038: mismatch detected for , In competitive hybridization assays, the ability to detect single mismatch is eightfold greater with this probe than with other molecular beacons. Native VLAN mismatch detected? John The easy part of answering your question is to confirm that yes if the router interface is in vlan 1 and the switch port is in vlan 50 that yes there is a vlan mismatch.

LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL , error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in compress.obj error LNK2038:� mismatch detected for 'name': The detect mismatch pragma is used to define such symbols and detect their conflicting values. Possible causes and solutions.

Comments
  • msdn.microsoft.com/en-us/library/6wtdswk0%28v=vs.71%29.aspx msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.71).aspx bugzilla.mozilla.org/show_bug.cgi?id=732124
  • I set my project's runtime library to Multi-threaded debug (that was the setting used in crypto++) and now it compiles! :) Thank you so much.
  • The problems occurred much earlier when you ran VCUpgrade. You are seeing symptoms of the VCUpgrade failure that was reported as a Success to you.
  • I am a bit confused. OP's error is LNK2038. As it does not happen with all libs, I suspect Crypto++ fiddles with some CRT settings that make it impossible to mix CRT flavours - usually it is just a warning (LNK4098) and you may be safe if you know what you do (not recommended, but possible with limitations, see e.g. stackoverflow.com/a/19944935/948581). I don't know why Crypto++ is affected this way, though.
  • @Tibo: These are not import libraries for DLLs; I believe Crypto++ is actually being linked statically with the program here. This means that any mismatch in the standard library being linked with in one module against another (probably) violates the "One Definition Rule". Which is bad. This used to be not an error, since the linker wasn't even able to detect this (the function/type names were the same, but their bodies and definitions differed significantly) until VC10 when the linker/librarian started "tagging" the modules it produced with extra information about the config of the build...
  • @Tibo: ... (continued from previous comment) For example, look at the first block of errors the OP is reporting. In there, "RuntimeLibrary" is a tag on both the Crypto++ library and the object file for the OP's program, and its value is "MDd_DynamicDebug" for one of them and "MTd_StaticDebug" for the other. This way, the linker that is trying to link two object files together can detect and report a whole new class of errors, given that the linkers that produced those object files tagged them with any relevant information, particularly any settings that would potentially violate ODR.
  • While I quite agree with you, there is still an area of mystery here. As for the OP's problem, I guess he is including "dll.h" from Crypto++, and then tries to link against the static lib instead of the DLL's import library. But I've seen the exact same errors on one computer, not on another one (VS2013 ultimate sp4 -> error, VS2013 community sp5 -> ok)...
  • @yzt I figured out a solution. Instead of using /ZW swicth, windows provides a way to use WinRT API via COM using a wrapper called WRL. It is just that not using /ZW makes coding little difficult since it hides COM implementation details, but it is possible to use WinRT without /ZW.
  • I followed the instructions in the cryptopp wiki, downloaded vs2010-dynamic.zip and pasted it's contents onto the cryptopp563 code. Built and got some source files missing. No problem the wiki says the zip is for the latest project on github, and just delete any missing files. Deleted. Now the project just doesn't build: 4 link errors, one example: error LNK2001: unresolved external symbol "void __cdecl OutputResultOperations(char const *,char const *,bool,unsigned long,double)" (?OutputResultOperations@@YAXPBD0_NKN@Z)
  • Turned out there was a bench.cpp that was missing from the project. But even after that it did not compile until I applied this fix to fiptest.cpp github.com/weidai11/cryptopp/pull/151/files?diff=split I wish they would make some order in this, like add the project zip files into git or something. And yes, I neglected to say my compiler is VS2015 update 2. Bottom line, follow the hints I wrote and it works.
  • @Yaniv - For the first comment, what do you recommend so other users don't experience problems? For the second comment, we plan on taking the patch once we get it fully tested. Is there anything we can do in the meantime? (I added additional info to this answer, but I want to ensure users don't have trouble).
  • Firstly, thanks so much for doing this. Crypto++ really rocks. Regarding the build problems, try to keep the windows sln and project files compatible with the latest files in the project, and since these change of course, these windows build should be somehow linked to the codebase, and maybe even be on the source tree. If that is too much, at least make sure the zip file with the visual studio build environment is compatible with the current stable official release.
  • Regarding the patch for fiptest.cpp - it seems to be something different about VS2015, so I guess anyone wishing to use VS2015 needs to apply this patch. It's just another case in an #ifdef block that seems to define the right debug callback for VS2015, and it's really easy to patch manually.