# Why CMake pass '-MD -MT' flags to gcc c++ and clang++ while compiling on Linux?

**URL:** https://discourse.cmake.org/t/why-cmake-pass-md-mt-flags-to-gcc-c-and-clang-while-compiling-on-linux/4998
**Category:** Development
**Created:** [February 14, 2022, 9:23am UTC](https://discourse.cmake.org/t/why-cmake-pass-md-mt-flags-to-gcc-c-and-clang-while-compiling-on-linux/4998 "2022-02-14T09:23:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JustLuoyu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/justluoyu/32/2178_2.png) [@JustLuoyu](https://discourse.cmake.org/u/JustLuoyu)
#### Post date: [February 14, 2022, 9:23am UTC](https://discourse.cmake.org/t/why-cmake-pass-md-mt-flags-to-gcc-c-and-clang-while-compiling-on-linux/4998/1 "2022-02-14T09:23:14Z")

</div>

To my knowledge, these seem to be MSVC’s runtime flags. I could not find them in GCC or clang’s manuals.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [February 14, 2022, 11:24am UTC](https://discourse.cmake.org/t/why-cmake-pass-md-mt-flags-to-gcc-c-and-clang-while-compiling-on-linux/4998/2 "2022-02-14T11:24:25Z")

</div>

These flags are used to generate dependencies.  
See [GCC Preprocessor options](https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html).

---

<div class="post-metadata">

### Author: ![gkaf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gkaf/32/3673_2.png) [@gkaf](https://discourse.cmake.org/u/gkaf)
#### Post date: [August 3, 2023, 6:59pm UTC](https://discourse.cmake.org/t/why-cmake-pass-md-mt-flags-to-gcc-c-and-clang-while-compiling-on-linux/4998/3 "2023-08-03T18:59:46Z")

</div>

Regarding the purpose of the generated dependency files, they are used so that generators (e.g. make, ninja) recompile files only when their included headers are modified.

There is a nice answer in stack overflow: [gcc - purpose of creating DEPENDENCIES\_OUTPUT file while compiling c program](https://stackoverflow.com/questions/9744244/purpose-of-creating-dependencies-output-file-while-compiling-c-program)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 7, 2023, 11:19am UTC](https://discourse.cmake.org/t/why-cmake-pass-md-mt-flags-to-gcc-c-and-clang-while-compiling-on-linux/4998/4 "2023-08-07T11:19:51Z")

</div>

> [@gkaf](#):
>
> they are used so that generators (e.g. make, ninja) recompile files only when their included headers are modified.

Not quite right. They are there to _additionally_ recompile the file when the included headers change. It may be recompiled for a variety of other reasons (flag change, source itself changes, etc.).
