views:

119

answers:

2

Very often, actually most of the times, Visual Studio2005 doesn't detect that some header included in some CPP file C++ project was changed. As the consequence, it doesn't recompile the project if only header is changed.

It doesn't depend on the "precompiled headers" settings. It doesn't happen in VS 2006 but in every version of VS 2005 and VS 2008 it does. It happens for all the projects, not for some specific one.

It doesn't happen if header file is a part of the project, i.e. if it appears in the vcproj file

The only way to resolve the issue is to perform a clean build.

Any advise is strongly appreciated.

+2  A: 

First of all VS only checks those headers that are part of your project (included in the project file/part of the file tree).

There are some header files that are handled in a very special manner, like for example the resource.h. This file has a comment tag at its beginning that defines the file as non-dependant. See my other question about that issue here on SO.

VS also caches the class dependencies (which class is declared in what header, which cpp uses what header, etc.) if you use the minimal rebuild compiler option (/Gm if I remember correctly). See this MSDN page on /Gm compiler setting for more details like this:

Minimal rebuild relies on class definitions not changing between include files. Class definitions must be global for a project (there should be only one definition of a given class), because the dependency information in the .idb file is created for the entire project. If you have more than one definition for a class in your project, disable minimal rebuild.

Also, I am not sure if dependencies are correctly resolved if you use the force include project setting...

Hope that was of any use.

fmuecke
"First of all VS only checks those headers that are part of your project (included in the project file/part of the file tree)" ----- this is not correct, sorry. VS observers all the header files, even if they are not part of the project but included in some cpp files. minimal rebuild is disabled. it must be something else. it is not resource header but plan header file. thanks
Moisei
A: 

Most of the time (especially in C projects) this happens because of the "Enable minimal rebuild" project setting. In "minimal rebuild" mode VS2005 tries to make more precise decisions over what needs to be rebuild: not based on which header files were modified, but rather based on which individual class definitions were modified. In C projects (as opposed to C++ ones) this approach fails basically 100% of the time, i.e. it completely ignores modified header files and never rebuilds anything. Very annoying. I don't know what kind of project you are building, but maybe it might fail in C++ projects as well.

Anyway, try setting "Enable minimal rebuild" to "No". (This is a project setting, BTW, not a global VS setting). This should revert VS to the traditional file-based rebuild behavior.

AndreyT
minimal rebuild was disabled - I just double checked.it must be something else.Thanks.
Moisei