Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing .cpp file causing Visual Studio 2012 to recompile unrelated files

Curious if anyone knows how to troubleshoot this; I have a particular .cpp file that, for some reason, whenever I modify it (even just adding a whitespace character) and build the project, causes a recompile of a host of other unrelated .cpp files (10-20 of them).

That file isn't #include'd in any other files (I never #include .cpp files directly, only .h) and there are no other dependencies I can think of - it seems to me like Visual Studio is misunderstanding the dependency tree, or has some corrupt internal state related to its build process. I've tried deleting the .sdf, .suo, ipch/, .user, and object file directories, but the problem appears again after a short time.

Modifying any other .cpp file causes a recompile of that file only, as expected.

I know a bit about MSBuild but don't see anything clearly amiss in the .vxproj file - the .cpp file in question only appears once in the ClCompile item group, and its header only appears once in the ClInclude group.

If this rings any bells, or if anyone has any tips on how I might go about tracking this down and troubleshooting it, it'd be greatly appreciated!

UPDATE:

I ran msbuild /verbosity:Detailed but unfortunately its explanation for why the unrelated files are getting compiled is just as opaque:

Using "CL" task from assembly "Microsoft.Build.CppTasks.Common.v110, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "CL"
Read Tracking Logs:
    Debug\cl.read.1.tlog
Output details (109 of them) were not logged for performance reasons.
{UnrelatedFile1.cpp} will be compiled as {PROBLEM_FILE.CPP} was modified at 4/30/2013 3:28:02 PM.
{UnrelatedFile2.cpp} will be compiled as {PROBLEM_FILE.CPP} was modified at 4/30/2013 3:28:02 PM.
(etc...)

If this makes sense to anybody let me know - can't seem to find much info on the inner workings of the CL task or why it would be seeing a dependency between these unrelated CPP files.

like image 605
QuadrupleA Avatar asked Nov 13 '22 06:11

QuadrupleA


1 Answers

This is likely because:

  • its part of another translational unit.
  • other projects reference the file(s).
  • something (perhaps a pre build event) is "touching" the files so that the compiler thinks they've changed.

Update: * Another reason is if the project has files "added" which are no longer on disk.

To debug this issue you'll need to turn on the highest level out output from msbuild:

http://blogs.msdn.com/b/msbuild/archive/2005/09/29/475157.aspx

http://msdn.microsoft.com/en-us/library/vstudio/ms164311.aspx

For example:

msbuild /verbosity:Detailed

Then msbuild will tell you why it wants to rebuild them.

Edit:

To answer your edit about the verbosity:Detailed output, you can check which files its including by using the /SHOWINCLUDES switch:

http://msdn.microsoft.com/en-us/library/hdkef6tk(v=vs.80).aspx

I assume there must be some header chain that causes the rebuild? Or perhaps the cause is else where in the verbosity:Detailed log.

like image 54
paulm Avatar answered Nov 14 '22 23:11

paulm