Header file inclusion static analysis tools?

后端 未结 8 542
旧时难觅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:50

    Personally I don't know if there is a tool that will say "Remove this file". It's really a complex matter that depends on a lot of things. Looking at a tree of include statements is surely going to drive you nuts.... It would drive me crazy, as well as ruin my eyes. There are better ways to do things to reduce your compile times.

    1. De-inline your class methods.
    2. After deinlining them, re-examine your include statements and attempt to remove them. Usually helpful to delete them, and start over.
    3. Prefer to use forward declarations are much as possible. If you de-inline methods in your header files you can do this alot.
    4. Break up large header files into smaller files. If a class in a file is used more often than most, then put it in a header file all by itself.
    5. 1000 translational units is not very much actually. We have between 10-20 thousand. :)
    6. Get Incredibuild if your compile times are still too long.

提交回复
热议问题