How to deal with precompiled headers accidentally getting corrupted on a canceled assembly?

I am using Visual C ++ 2012 with a project that heavily uses precompiled headers. So hard that the infamous / Zm is used .

When I cancel an assembly, I sometimes get this error in the following assembly:

error C1852: 'foo.pch' is not a valid precompiled header file 

Nine times out of ten, everything will go smoothly, but when that happens, I have to find .pch and remove it manually before restarting the build.

It annoys me a little. Is there any way to prevent this? Patch from Microsoft? Or is there a way to force Visual to remove .pch and automatically restart the assembly when a problem occurs? Or some other solution that I did not think about?

EDIT: here's the version of Visual I am running:

 Microsoft Visual Studio Professional 2012 Version 11.0.61030.00 Update 4 
+8
c ++ visual-c ++ pch visual-c ++ - 2012
source share
3 answers

I followed Rockeye's hint about trying to find a template in these damaged files. It turns out that this is very simple: valid files start with the VCPCH0 header, no corrupted files.

A simple C # program running as the Pre-Build event of a failed project (s) and deleting corrupted files solves the problem. If anyone is interested, the source is right here .

0
source share

This is a pure hypothesis, since I have not come across this problem.

Try to find out how Visual detects a damaged .pch file (i.e. an empty file, the file is not finished, ...). If it matches a clear pattern, write a pre-build script that will analyze all .pch and remove the corrupted ones.

+1
source share

I would create a script that would try to recompile the stdafx.cpp file, but this time using PCH instead of creating it. That is, the expected result is a successful compilation of an empty file. If this fails, remove PCH. Now run this script as a pre-build step.

It sounds pretty expensive, but it's very reliable. Any problem loading PCH causes it to regenerate, even updating the compiler. In addition, your PCH is now in the file cache, which means that the actual use is a little cheaper.

This can be implemented as an assembly of an NMAKE script with somewhat unusual rules.

+1
source share

All Articles