views:

504

answers:

6

In some of my VS 2005 projects, when I change an include file some of the cpp files are not rebuilt, even though they have a simple #include line in them.

Is this a known bug, or something strange about the projects? Is there any information about how VS works out the dependencies and can I view the files for that?

btw I did try some googling but couldn't find anything about this. I probably need the right search term...

+2  A: 

To be honest I never faced such a problem using Visual Studio. Your CPP should be rebuild as well if it includes the header. The only reason I can come up with: same include file is taken from 2 different sources.

You can try do debug this at compile time, by enabling the preprocessor to output preprocessed files. Click on the CPP file go to properties and then to C/C++->Preprocessor and select in "Generate Preprocessed File" the item with or without line numbers.

Go to you include file put the pragmas around your newly added definitions like:

#pragma starting_definition_X
...
#pragma ending_definition_X

Now compile everything. There will be a newly created file with the same name as CPP but with extension .I (or .i).

Make a search if your pragmas are there. If not, your include come from another place.

If you use pre-compiled headers, you cpp should rebuild. There is also a pragma once statement in MS VC, which parses the include file only once, but that should still recompiler you cpp-file.

Hope that helps,
Ovanes

ovanes
The header files all use #pragma once or #ifdef guards so I don't think this is the cause of the problem. Interesting though that the preprocessor output can be stored: thanks that may come in handy in future...
danio
Yes, I used it a lot when did some type of mixed pre-processor metaprogramming and common meta-programming. This was the only way to debug the code generation. The nice thing is that you can put any pragmas inside the header or cpp file, and find them later in pre-processed file, since preprocessed files are usually very large, due to optimizations compiler allocates huge file and inserts expanded includes there, otherwise it has to re-write the file every time smth is inserted in the middle. Since pragmas stay in the pp-file, you can simple search for them and find your snippet of interest.
ovanes
A: 

Visual studio compares the timestamps on the files. So you might want to check that your system clock is set correctly and also that none of the files has a funny timestamp on it. Look at the include files, the cpp files, the pch files and obj files and make sure all the timestamps look reasonable. In particular, make sure none of them are in the future.

Paul Mitchell
thanks but times look OK. .h is newer than .obj which is newer than .cpp. We're not using pch here.
danio
+1  A: 

I've experienced this problem from time to time, and with other IDEs too, not just VS. It seems thatv their internal dependency tree sometimes gets out of whack with reality. In these cases, I've found deleting pre-compiled headers (this is important) and doing a complete rebuild always solves the problem. Luckily, it doesn't happen often.

anon
Yeah complete rebuild fixes it but takes about 40 minutes. I'm trying to get unattended builds going on my machine.
danio
@danio: I remember having such problems. In that case I either restarted Visual Studio or did the rebuild. Why do you have to rebuild all? Can't you just rebuild the project only?
ovanes
@ovanes Yes rebuilding just the problem projects is quicker but finding them out can be time consuming. Have to decrypt the linker errors to work out which libraries are in error, rebuild each of those, then rebuild solution and hope I've caught them all.
danio
+1  A: 

Do you have the "Minimal rebuild" option turned on?

rpg
No but the idb file still seems to be generated. I will see if I can get anywhere with these files...
danio
A: 

Was the .h files added in the project? If not, then vs maybe unable to find out the dependency.

leiz
No they're not in the project (don't ask...). I don't think that should be necessary though.
danio
A: 

Thanks for all the answers they have helped point me in the right direction.

I have discovered that deleting the idb file and rebuilding will then allow subsequent modifications of .h files to cause the correct .cpp files to be built. However this causes the entire project to be rebuilt which just brings me back to Neil Butterworth's suggestion of doing a full rebuild. I don't think there is much else I can do about it.

As an aside, looking at the bad and good idb files I can see that the cpp file that was not being built is not in the bad idb, whereas it is in the good idb. The header file that is being changed is mentioned several times in both files.

win_pdbx (download) can extract the idb file and moyix has published some information about the streams in these files. Stream 4 contains the file paths of the cpp files but I have not been able to determine the format.

danio