Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "g++ -MMD" better than include scanning?

Whilst looking at build systems, a lot of them (SCons, bjam, cmake, Tundra, etc) have a built-in #include scanner. Yet gcc & icc offer a -MMD (or -MD) option which outputs the names of the header files that the C++ file depends upon.

The -MMD dependency option seems to be reliable. If you add a #include to a C file, its timestamp would change so the build system would recompile it. If you add a #include to a header file, its timestamp would change and it would recompile all affected C files.

Include scanning systems break, but -MMD would seem to me to be robust. Which is best, and why?

like image 367
ACyclic Avatar asked Aug 24 '12 08:08

ACyclic


1 Answers

-MMD is best, for the reasons you give and more.

Getting the compiler to output dependencies as part of the normal compilation process ensures that the exact same set of compiler options such as -I paths and macros are in effect for compilation and when finding dependencies. That's less redundant and less error-prone than ensuring the same options are used for two separate tools.

like image 148
Jonathan Wakely Avatar answered Sep 22 '22 20:09

Jonathan Wakely