[CMake] Force MSVC runtime for debug builds

Michael Jackson mike.jackson at bluequartz.net
Tue Nov 8 14:01:47 EST 2016


I would agree. I don't know how many subtle runtime bugs I have had to 
figure out because our project mixed debug and release runtimes on MSVC. 
DON'T do it unless you REALLY have to. But even then I would never 
actually deploy that into production.

YMMV
-- 
Mike Jackson  [mike.jackson at bluequartz.net]


clinton at elemtech.com wrote:
>
>
> ----- On Nov 7, 2016, at 1:37 AM, Stephan Menzel
> <stephan.menzel at gmail.com> wrote:
>
>     Hello everyone,
>     I'm looking for a way to force Debug configurations in generated
>     MSVC solutions to use the Release runtime instead of the default
>     "Debug". e.g. /MD rather than /MDd.
>
>     My use case is an ever recurring problem of creating libraries that
>     are linked in plug-in fashion against Release only applications. I
>     want for my Debug configuration to have debug info and no
>     optimization but still use the release runtime so I can link them.
>
>     I tried replacing /MDd with /MD in CMAKE_CXX_FLAGS_DEBUG. This
>     yielded objects built with /MD alright but failed to link into an
>     executable with stuff like that:
>
>     error LNK2038: mismatch detected for 'RuntimeLibrary': value
>     'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in Test.obj
>
>      From what I gather all the obj are actually compiled for Release
>     runtime without optimization and Debug info just like I need it. But
>     then the main obj is built and linked in Debug mode, causing the
>     executable to not be created.
>
>     Is there a way to solve this? Like a generic CMake executable flag
>     or something that I can use to force the other runtime?
>
>     Please note that using RelWithDebInfo and turning off optimization
>     is not exactly what I need as I still want that mode much the way it is.
>
> If you are going to use /MD instead of /MDd, then you probably also need
> to remove the _DEBUG preprocessor flag.
> IIRC, I've seen cases where defining _DEBUG includes symbols only
> defined by the debug runtimes.
>
> Clint
>


More information about the CMake mailing list