Bad PCH usage detected

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in Insure++
Pre-compiled headers
WARNING: Bad PCH usage detected, .\MyFile.cpp will not be instrumented.

This error is caused by the use of pre-compiled headers in a Microsoft VS build. The use of PCH interferes with Insure++'s ability to properly instrument your code so this warning message is shown.

To solve it you simply need to turn off the use of pre-compiled headers, build clean and then rebuild with Insure++.


  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    I'm sorry, but that's not true.

    "Warning: Bad PCH usage" occurs when somebody tries to use a precompiled header before it has been built. e.g:

    > insure -Yustdafx.h foo.cpp

    before doing this:

    > insure -Ycstdafx.h stdafx.cpp

    will cause the driver to spit out that message. There are other situations that will also cause this message, such as the following:

    > insure -Ycstdafx.h stdafx.cpp
    > cl -Ycstdafx.h stdafx.cpp
    > insure -Yustdafx.h foo.cpp # instrumented pch is now out of date

    PR40798 documents the reason for this. In brief, it is to handle silly users who mix Insure++ pch builds and normal pch builds willy-nilly.

    Disabling PCH will cause the warning message to go away, but it should not be necessary. Users should be aware that rebuilding the PCH without Insure++ will cause Insure++ to treat it's own instrumented precompiled header as out of date. To avoid this, always build the instrumented precompiled header before using it, and do not build a non-instrumented precompiled header before attempting to use an instrumented one without also building an instrumented precompiled header.

    If you find this confusing, the best thing you can do is have a separate configuration for Insure++ builds and normal Debug builds. This will help avoid building instrumented stdafx.pch and uninstrumented stdafx.pch willy-nilly.
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Some people are confused by this post. "Bad PCH usage" is different than PCH_ERROR. The former is addressed in this FAQ. The latter means an unsupported PCH configuration is being used. Refer to the manual for details. It may be possible to create a supported PCH configuration without much effort.

    When in doubt, turn pch off, but make sure the project is able to build normally without using PCH before complaining that the project doesn't build under Insure++ when PCH is turned off. Some broken projects will only build if PCH is turned on. Such projects are usually just poorly configured and should be fixed anyway, IMO.
This discussion has been closed.