[CMake] Force MSVC runtime for debug builds

Kim Kryger kimberly.kryger at gmail.com
Mon Nov 14 16:05:07 EST 2016


I ran into this today. I tried to use /MD to link against a custom md
library, but because _DEBUG was defined *by CMake* I couldn't use it out of
the box.

Why is CMake defining _DEBUG for MSVC projects anyways? _DEBUG is
automatically defined when using /MDd, and I don't believe it should be
defining it itself. I've had to remove it for multiple projects because
it's making assumptions as to what I want defined.


Default for CMAKE_CXX_FLAGS_DEBUG_INIT
/D_DEBUG /MDd /Zi /Ob0 /Od /RTC1

I don't think that first define should be there.


Reference:
https://github.com/Kitware/CMake/blob/5d29506811c5b75ae48e12de6c317f6440874215/Modules/Platform/Windows-MSVC.cmake#L294
https://msdn.microsoft.com/en-us/library/0b98s6w8.aspx


On Fri, Nov 11, 2016 at 9:42 AM, Stephan Menzel <stephan.menzel at gmail.com>
wrote:

>
> On Tue, Nov 8, 2016 at 4:21 PM, <clinton at elemtech.com> wrote:
>>
>> 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
>>
>
> What a surprise. Removing _DEBUG did the trick. I was under the impression
> _DEBUG only controls Microsoft STL impl's debug iterator stuff but
> apparently it also makes the resulting exe link with /MD rather than /MDd.
> Guess that was wrong.
>
> So yes, problem solved.
>
> Thank you!
>
> Stephan
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161114/2e129173/attachment.html>


More information about the CMake mailing list