Reputation: 23951
I tried to link a library (let's call it LibB
) to a program (TheProgram
) that already linked another library (LibA
).
The debug configuration builds fine, but in release mode I get this error:
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in TheProgram.obj
I thought that's easy to fix, because I only need to make sure that each of the linked objects are built with /MT. I did, and they all are. I also checked if there are any per-file settings that have the runtime flag differently in this configuration - there aren't. Also checked the final command line in the build - it's /MT everywhere.
Even more interestingly, if I link the debug version of LibB
(while building the Release configuration), this error disappears, but I get other errors.
What could cause the mismatch despite the matching flags everywhere?
Upvotes: 3
Views: 111
Reputation: 23951
This drove me crazy and took days to discover. I wanted to share this here, because there is an abundance of questions where the problem is actually mismatching /M* flags, but that was not the case here.
The mistake was that I added a new preprocessor define in Debug mode, then copied over the whole field to the Release configuration (not wanting to fiddle with the mouse selection). This field contained _DEBUG
(instead of NDEBUG
) and that caused the linker to detect that /MTd was being linked. When I changed _DEBUG
to NDEBUG
in the Preprocessor Definitions in Release mode, the problem was solved.
As a side note, I tried to find the error in git diff
, because I had a pretty good idea which commit introduced it, but it was very hard to see without a word-by-word diff due to the nature of the VS project file format. One colleague spotted this define for me, but he also pointed me to this answer about highlighting word differences in git diff, I think this can be very useful to find problems like this.
Upvotes: 3