为什么 Visual Studio 2008 总是重建我的整个项目?
我有一个包含大约 60 个 C++ 源文件的 Visual Studio 项目。 我可以进行构建,并且它可以毫无错误地完成。 但如果我立即再次按 F7,它总是会重新编译大约 50 个源文件。 它不会重新编译所有文件,这很奇怪。
我设置了“启用最小重建”(/Gm)。 有什么想法为什么会这样做吗? 所有文件都没有将来的修改日期。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
原因是,如果将其中一个源文件的“上次修改日期”设置为将来的某个日期:它会重建,然后源文件仍然晚于可执行文件。
如果源文件位于远程计算机(网络共享)的目录中,则可能会出现日期问题,并且/或者如果您的计算机时间与运行服务器的计算机的日期不同步,甚至可能会出现此问题您的源版本控制系统。
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.
检查您的项目是否包含磁盘上不存在的任何 .h 头文件。 当我删除一个头文件时,我总是会遇到这种情况,我实际上没有在任何地方包含它,但忘记从 VS 的解决方案导航器中删除它。 注意:缺少标头在构建过程中不会产生错误(当任何地方都没有 #included 时)。
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).
检查项目的程序数据库文件名设置。 由于某种原因,如果将其设置为目录名称(例如
"$(IntDir)\"
),有时会导致 VS 每次都重新构建项目,即使您是不生成 PDB 文件(即调试信息格式设置为“禁用”)。这是VS2008的一个bug; 我还没有在 VS2010 中重现它,但我的测试还不够彻底,所以我不能自信地说该行为在 VS2010 中不存在。
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.
导致我出现类似症状的原因是:
我的解决方案中有几个项目。 有超过 1 个项目引用(并因此编译)的 .cpp 文件。 不幸的是,Visual Studio 创建的 .obj 文件的命名非常简单 - 它只是将“.cpp”替换为“.obj”。 创建具有不同名称的包装器 .cpp-s 解决了问题。
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.
我有类似的事情。 尽管我确实有构建前和构建后事件,但它们并没有引起问题。 事实证明,我在参考链中有许多项目,这些项目的内容文件被标记为“始终复制”而不是“如果较新则复制”,这意味着这些项目始终被认为是“过时的”。 通过将所有这些更改为“如果较新则复制”,对我的单元测试项目的更改不再强制重新编译所有其他项目。
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.
禁用“最小重建”(配置属性 > C/C++ > 代码生成)为我解决了这个问题。 编译器甚至留下了线索:
1>cl : 命令行警告 D9007 : '/Gm' 需要 '/Zi 或 /ZI'; 。
尽管我必须指出,编译器并没有像它所说的那样忽略该选项
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.
就我而言,我将系统数据时间更改为之前的日期,因此每次都会重建,因为文件的时间戳不同,一旦更改为当前时间,它就不会每次都重建。
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.
我们经常这样做:
We have that here regularly:
有同样的问题。 解决方法:
-删除输出文件夹(obj、exe、所有文件)
-运行cygwin
-cd 项目文件夹
-运行“touch *”,重置文件修改日期/时间
-构建并享受修复的问题
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
项目重建也存在类似的问题。
每次按 F7 时,Visual Studio 不会重新编译,而是重新链接项目。
修复很简单。 尝试在编辑器中打开项目中包含的所有文件(从解决方案资源管理器中双击每个文件)并从解决方案中删除那些不存在的文件。
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.
您的文件日期是否是未来的? 如果您更改了时区或更改了系统时钟时间,则可能会发生这种情况。 未来的日期会让 IDE 感到困惑,并在每次按下 F7 或 F5 时强制重建。
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.
我已经解决了同样的问题。
在我的例子中,编译器显示警告,如果指定了 /Gm,则需要 /Zi 选项。
/Gm 启用“最小重建”,这需要 .pdb 文件中的调试信息。 因此,如果您不想使用 .pdb,也可以禁用最小重建 - 它解决了我的问题。
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.
最有可能的是依赖问题。
请考虑以下可能性:
如果您为解决方案中的某些文件定义了自定义构建工具,请确保输出属性包含正确的文件名。 如果构建工具的输出与输出文件名中指定的输出不对应,构建器将重建该文件。
如果您有自定义构建事件,请检查这些构建事件的输出是否不会影响要构建的文件的依赖项。
如果您有自定义构建事件,请检查这些构建事件的输出是否不会影响要构建的文件的依赖关系
在构建后尝试将某些输出文件复制或移动到构建文件夹时,我遇到了问题。 影响构建过程的输出文件时间戳的构建后操作将决定每次重建。
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.
在我的这种效果的情况下(通过 VS2005 的 C++),它仅在发布配置上,并且 Studio 在构建输出中告诉,如果未设置 /Zi - 选项,则忽略编译器选项 /Gm。 通过
配置属性设置 /Zi 后 -> C/C++-> 一般-> 调试信息格式:程序数据库(/Zi),
没问题。 但是,当发布配置需要有关调试的内容时,难道没有什么问题吗? 我还不清楚!
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!
项目属性-> “C/C++”-> “输出文件”-> “程序数据库文件名”选项不应为空。 通过从下拉框中选择来设置此选项。 该选项将设置如下:$(IntDir)\vc90.pdb。 并且 ProgramDataBaseFileName="" 行将从 vcproj 文件中删除。
然后,当您构建项目或解决方案时,只会重新编译更改的 *.cpp 文件。
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.
看来这个问题可能是由很多原因引起的,但为我解决的是:
bin
和obj
文件夹(Clean 似乎没有解决问题)注意:这是针对 C# 的Visual Studio 2010 中的程序。
It seems that this problem can be caused by many things, but what fixed it for me was:
bin
andobj
folders (Clean doesn't seem to do the trick)Note: This was for a C# program in Visual Studio 2010.
经过几天的谷歌搜索,我最终找到了解决我的问题的方法。
当我将项目转移到新电脑时,我遇到了这个问题。 我多次检查了文件的创建日期。 这些日期是最新的,但是即使我更改了文件,修改日期也在最底层(有点奇怪)。
对文件进行简单更新即可解决该问题。
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.
我也遇到了同样的问题,看来是因为我关闭了浏览信息。 属性->C/C++->浏览信息->启用浏览信息->无。 我发现的唯一解决办法就是重新打开它。 这是针对 xbox 360 项目的,fwiw,我的其他项目没有这个问题。
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.