I agree that CMake should not be defining _DEBUG explicitly, as it is used by Microsoft’s headers to match the chosen runtime. Maybe this warrants a bug report on gitlab.
From: CMake [mailto:[email protected]] On Behalf Of Kim Kryger Sent: Monday, November 14, 2016 22:05 To: Stephan Menzel <[email protected]> Cc: cmake <[email protected]> Subject: Re: [CMake] Force MSVC runtime for debug builds 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 <[email protected]<mailto:[email protected]>> wrote: On Tue, Nov 8, 2016 at 4:21 PM, <[email protected]<mailto:[email protected]>> 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<http://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
-- 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
