Header file inclusion static analysis tools?

后端 未结 8 538
旧时难觅i
旧时难觅i 2020-12-02 17:42

A colleague recently revealed to me that a single source file of ours includes over 3,400 headers during compile time. We have over 1,000 translation units that get compiled

8条回答
  •  渐次进展
    2020-12-02 17:56

    GCC Has a flag (-save-temps) with which you can save intermediate files. This includes .ii files, which are the results of the preprocessor (so before compilation). You can write a script to parse this and determine the weight/cost/size of what is included, as well as the dependency tree.

    I wrote a Python script to do just this (publicly available here: https://gitlab.com/p_b_omta/gcc-include-analyzer).

提交回复
热议问题