Is “g++ -MMD” better than include scanning?

烈酒焚心 提交于 2019-12-12 11:17:11

问题


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?


回答1:


-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.



来源:https://stackoverflow.com/questions/12106141/is-g-mmd-better-than-include-scanning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!