简体   繁体   中英

How does visual studio know which cpp files to rebuild when an include file is changed?

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...

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

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.

您是否打开了“最小重建”选项?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM