Why is Visual Studio 2008 always rebuilding my whole project?

不问归期 提交于 2019-12-20 12:42:25

问题


I have a Visual Studio project with about 60 C++ source files. I can do a build, and it completes without errors. But if I immediately hit F7 again, it always re-compiles about 50 of the source files. It doesn't re-compile all of the files, which is strange.

I have 'Enable minimal rebuild' (/Gm) set. Any ideas why it might be doing this? None of the files have a Modified Date in the future.


回答1:


Are any of your file dates in the future? This can occur if you changed time zones or changed the system clock time. Dates in the future will confuse the IDE and force a rebuild every time F7 or F5 is hit.




回答2:


I've solved the same problem.

In my case compiler displayed warning, that /Zi option is required if /Gm is specified.

/Gm enables "minimum rebuild", which requires debug information in .pdb file. So, if you don't want to use .pdb, also disable minumum rebuild - it solved a problem in my case.




回答3:


Most probably is a matter of dependencies.

Consider the following possibilities:

  • If you have custom build tools defined for some of the files in your solution, make sure that the output property contains the right file name(s). If the output of the build tool doesn't correspond to the one(s) specified in the output file names, the builder will rebuild that file.

  • If you have custom build events, check whether the output from those build events don't affect the dependencies of the files to be built.

  • I had problems when trying, at post-build, to copy or move some of the output files to a build folder. The post build operations that affect the timestamp of the ouput files of the build process will determine rebuild each time.




回答4:


In my case of such effect (C++ via VS2005) it was on Release configuration only, and the Studio tells in the build output, that compiler option /Gm is ignored if /Zi - option is not set. After setting /Zi via

Configuration Properties -> C/C++ -> General -> Debug Information Format : Program Database (/Zi) ,

it was ok. But isn`t there something wrong, when the Release Configuration needs something about Debugging? Not yet clear to me!




回答5:


Project Properties -> "C/C++" -> "Output Files" -> "Program Database File Name" option should not be empty. Set this option by selecting from drop-down box . The option will be set like this: $(IntDir)\vc90.pdb. And line ProgramDataBaseFileName="" will be removed from vcproj file.

Then only changed *.cpp files will be recompiled when you build the project or solution.




回答6:


It seems that this problem can be caused by many things, but what fixed it for me was:

  1. Closing Visual Studio
  2. Manually deleting all bin and obj folders (Clean doesn't seem to do the trick)
  3. Opening the solution and running Clean (I'm not sure if this is necessary, but I did it just in case...)
  4. Building like normal

Note: This was for a C# program in Visual Studio 2010.




回答7:


After a couple days of googling, I ended up with a solution to my problem.

I encountered this problem when I moved my projects to a new PC. I had checked several times the creation date of the files. These dates were up-to-date, however the modification dates were in the bast (kinda bizarre) even when I changed the files.

A simple update of the files resolved the problem.




回答8:


I'm having the same problem, and it seems to be because I've turned browse information off. Properties->C/C++->Browse Info->Enable Browse Info->None. The only fix I've found is turning it back on. This is for an xbox 360 project, fwiw, my other projects don't have the problem.




回答9:


A reason is if the 'date last modified' for one of the source file is set for some date in the future: it rebuilds, and then the source file is still later than the executable.

This problem with the dates can happen if the source file is located in a directory a remote machine (a network share), and/or may even happen if your machine's time isn't synchronised with the date of the machine which is running the server of your source version control system.




回答10:


Check your project includes any .h header file that doesn't exist on disk. Always happens to me when I delete a header file I'm not actually including anywhere, but forget to delete it from my solution navigator in VS. Note: missing headers produce no errors during the build (when not #included anywhere).




回答11:


Check your project's Program Database Filename setting. For some reason, if this is set to the name of a directory (such as "$(IntDir)\"), it can sometimes cause VS to rebuild your project every time, even if you're not generating PDB files (i.e. Debug Information Format is set to "Disabled").

This is a bug in VS2008; I have not yet reproduced it yet in VS2010, but my tests haven't been thorough, so I'm not confident saying that the behavior isn't present in VS2010.




回答12:


What caused similar symptoms at me was: I have several projects in a solution. There were .cpp files which were referenced (and therefore compiled) by >1 projects. Unfortunately Visual Studio creates .obj files with a very simple naming - it just replaces ".cpp" by ".obj". Creating wrapper .cpp-s with different named solved the problem.




回答13:


I had something similar. Even though I did have pre and post build events, they weren't causing the issue. It turned out that I had a number of projects down the reference chain that had content files that were marked as "copy always" instead of "copy if newer" meaning that these projects were always considered "out of date". By changing all of these to "copy if newer", changes to my unit test project no longer forced a recompile of all of the other projects.




回答14:


Disabling "minimal rebuild" (Configuration Properties > C/C++ > Code Generation) fixed it for me. The compiler even left a clue:

1>cl : Command line warning D9007 : '/Gm' requires '/Zi or /ZI'; option ignored

Although I must point out, the compiler did not ignore the option as it said.




回答15:


In my case I changed system data time to previous date so it is rebuilding every time because of different time stamp of the files once changed to the current time its not rebuilding every time.




回答16:


We have that here regularly:

  • delete all intermediate and output files by hand. The clean option in vstudio is sometimes not enough. From a fresh start do the complete build. If after a complete build vstudio still wants to recompile certain files it might be related to next bullet.
  • if in your vcxproj a header file is referenced which is not on disk, the project is also recompiled. You might check this by some hidden feature described on MSDN blogs or just touch (i.e. click on it to open) all header files in the project exploder and see if one does not exist on disk



回答17:


Had the same problem. Solved by: -delete output folder (obj,exe,all files) -run cygwin -cd project folder -run "touch *", which reset file modify date/time -build and enjoy problem fixed




回答18:


There is similar issue with project rebuild. Visual Studio does not recompile but re-links a project every time on F7 hit.

Fix is simple. Try to open in Editor all files included into project (from Solution Explorer double click on each file) and remove from solution those files which do not exist.



来源:https://stackoverflow.com/questions/1022485/why-is-visual-studio-2008-always-rebuilding-my-whole-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!