Reputation: 16266
I added a new configuration DebugWithReleaseCRT
to our CMake scripts, which is based on pretty standard Debug
config but links with Release CRT (/MD
instead of /MDd
) and defines _ITERATOR_DEBUG_LEVEL=0
. I checked generated project file settings and all looks good:
C/C++ -> Code Generation -> RuntimeLibrary = Multi-Threaded DLL (/MD)
However when I build it I get errors like:
3>3rd-party.lib(3rd-party.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in My.obj
which I read as:
your
My.cpp
file is compiled with debug CRT (MDd_DynamicDebug
) while you're trying to link with library3rd-party.lib
that is built with release CRT (MD_DynamicRelease
)
I also checked this particular file (My.cpp
) settings but nothing fancy there, it inherited /MD
flag from the parent project.
Why my project is linked with Debug CRT despite of specified /MD
flag?
Upvotes: 0
Views: 270
Reputation: 16266
The problem is related with VS precompiler definition _DEBUG
The compiler defines _DEBUG when you specify the /MTd or /MDd option. These options specify debug versions of the C run-time library.
As my DebugWithReleaseCRT
config was based on Debug
, it copied _DEBUG
definition too. Turns out that if _DEBUG
is defined it overrules /MD
flag (MD_DynamicRelease
) and VS still links with debug CRT (hey Visual Studio team, that was a surprise!).
The problem was solved by removing _DEBUG
from DebugWithReleaseCRT
. Actually it was solved by replacing _DEBUG
by NDEBUG
because some 3rd-party dependencies required exactly one of them to be defined. I'm still not sure it's a clean way to configure DebugWithReleaseCRT
, I don't feel particularly confident about defining NDEBUG
in kind of debug config.
Upvotes: 1