How do YOU reduce compile time, and linking time for Visual C++ projects (native C++)?

前端 未结 12 1193
深忆病人
深忆病人 2020-11-29 21:46

How do YOU reduce compile time, and linking time for VC++ projects (native C++)?

Please specify if each suggestion applies to debug, release, or both.

12条回答
  •  星月不相逢
    2020-11-29 22:14

    These solutions apply to both debug and release, and are focused on a codebase that is already large and cumbersome.

    Forward declarations are a common solution.

    Distributed building, such as with Incredibuild is a win.

    Pushing code from headers down into source files can work. Small classes, constants, enums and so on might start off in a header file simply because it could have been used in multiple compilation units, but in reality they are only used in one, and could be moved to the cpp file.

    A solution I haven't read about but have used is to split large headers. If you have a handful of very large headers, take a look at them. They may contain related information, and may also depend on a lot of other headers. Take the elements that have no dependencies on other files...simple structs, constants, enums and forward declarations and move them from the_world.h to the_world_defs.h. You may now find that a lot of your source files can now include only the_world_defs.h and avoid including all that overhead.

    Visual Studio also has a "Show Includes" option that can give you a sense of which source files include many headers and which header files are most frequently included.

    For very common includes, consider putting them in a pre-compiled header.

提交回复
热议问题