Is there a way to use pre-compiled headers in VC++ without requiring stdafx.h?

后端 未结 9 774
予麋鹿
予麋鹿 2020-12-05 16:20

I\'ve got a bunch of legacy code that I need to write unit tests for. It uses pre-compiled headers everywhere so almost all .cpp files have a dependecy on stdafx.h which is

9条回答
  •  误落风尘
    2020-12-05 16:53

    When you normally use precompiled headers, "stdafx.h" serves 2 purposes. It defines a set of stable, common include files. Also in each .cpp file, it serves as a marker as where the precompiled headers end.

    Sounds like what you want to do is:

    • Leave precompiled header turned on.
    • Leave the "stdafx.h" include in each .cpp file.
    • Empty out the includes from "stdafx.h".
    • For each .cpp file, figure out which includes were needed from the old "stdafx.h". Add these before the #include "stdafx.h" in each .cpp file.

    So now you have the minimal set of dependancies, and you still are using precompiled headers. The loss is that you are not precompiling your common set of headers only once. This would be a big hit for a full rebuild. For development mode, where you are only recompiling a few files at a time, it would be less of a hit.

提交回复
热议问题