visual-studio 为什么 msbuild 和 link.exe 在构建过程中“挂起”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1080757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:43:30  来源:igfitidea点击:

Why is msbuild and link.exe "hanging" during a build?

c++visual-studiomsbuildbatch-filelinker

提问by Tim

We have a few C++ solutions and we run some build scripts using batch files that call msbuild.exe for each of the configurations in the solutions.

我们有一些 C++ 解决方案,我们使用批处理文件运行一些构建脚本,这些文件为解决方案中的每个配置调用 msbuild.exe。

This had been working fine on 3 developer machines and one build machine, but then one of the projects started to hang when linking. This only happens on the newest machine which is a quad core, 2.8ghz I think. It runs on Windows Server 2003 and the others are on XP or Vista.

这在 3 台开发机器和一台构建机器上运行良好,但随后其中一个项目在链接时开始挂起。这只会发生在最新的四核机器上,我认为是 2.8GHz。它运行在 Windows Server 2003 上,其他运行在 XP 或 Vista 上。

This happens consistently even if I change the order of builds in the bat file.

即使我更改了 bat 文件中的构建顺序,这种情况也会持续发生。

If I run the build from the IDE on that machine it does not hang.

如果我从那台机器上的 IDE 运行构建,它不会挂起。

Any ideas about what could possibly be causing this?

关于可能导致这种情况的任何想法?

I am using Visual Studio 2008.

我正在使用 Visual Studio 2008。



Edit:

编辑:

I see now that when it is hung the following are running:

我现在看到,当它挂起时,以下正在运行:

  • link.exe (2 instances) One with large memory usage and one with a small amount of memory usage.
  • vcbuild.exe
  • msbuild.exe
  • vcbuildhelper.exe
  • mspdbsrv.exe
  • link.exe (2 个实例) 一个内存使用量大,一个内存使用量小。
  • vcbuild.exe
  • msbuild.exe
  • vcbuildhelper.exe
  • mspdbsrv.exe


Edit:

编辑:

The exe file exists and so does the pdb file.

exe 文件存在,pdb 文件也存在。

The exe file is locked by some process, and I can't delete it or move it. I can delete the pdb file though.

exe 文件被某个进程锁定,我无法删除或移动它。我可以删除 pdb 文件。

I also have the problem if I just use VCBuild.exe.

如果我只使用 VCBuild.exe,我也会遇到问题。

I decided to try debugging the 2 link.exe processes and the mspdbsrv.exe processes.

我决定尝试调试 2 个 link.exe 进程和 mspdbsrv.exe 进程。

When I attached the debugger/MSdev IDE to them I got a message box saying that the application was deadlocked and/or that "all threads have exited".

当我将调试器/MSdev IDE 附加到它们时,我收到一个消息框,说应用程序已死锁和/或“所有线程都已退出”。

I guess I will have to check for a service pack for that msdev install on that machine.

我想我将不得不检查该机器上安装的 msdev 的服务包。



Edit:

编辑:

In the debug.htm output file I get all sorts of stuff output after the link.exe command is generated.

在 debug.htm 输出文件中,我在 link.exe 命令生成后得到了各种输出。

However, for the release buildlog.htm the linke.exe line is the last line.

但是,对于版本 buildlog.htm,linke.exe 行是最后一行。

This is clearly a hang in the linker. Definitely a Microsoft bug.

这显然是链接器中的一个问题。绝对是微软的bug。

I am now trying to figure out what the .rsp (linker response) file is.

我现在想弄清楚 .rsp(链接器响应)文件是什么。

When I issue:

当我发出:

link.exe @c:\\Release\RSP00000535202392.rsp /NOLOGO /ERRORREPORT:QUEUE

link.exe @c:\\Release\RSP00000535202392.rsp /NOLOGO /ERRORREPORT:QUEUE

That is the last line in the release build log. The debug one has lots more information after that.

这是发布构建日志中的最后一行。在那之后,调试一个有更多的信息。

Reinstalling a different version of Visual Studio did not solve the problem.

重新安装不同版本的 Visual Studio 没有解决问题。

I will open an issue/ticket with Microsoft. I will post an answer if I can.

我将与 Microsoft 开一个问题/票证。如果可以,我会发布答案。

回答by Roger Lipscombe

Whole-program optimization (/GL and /LTCG) and /MP don't mix -- the linker hangs. I raised this on Connect.

整个程序优化(/GL 和/LTCG)和/M​​P 不混合——链接器挂起。我在Connect上提出了这个问题。

The upshot is that it's a confirmed bug in VS2008; contact PSS if you want a hotfix; and the fix is included in VS2010.

结果是它是 VS2008 中的一个已确认的错误;如果您需要修补程序,请联系 PSS;并且此修复程序包含在 VS2010 中。

If you can't wait that long, turn off /MP (slower compiles) or /LTCG (slower code).

如果您不能等那么久,请关闭 /MP(较慢的编译)或 /LTCG(较慢的代码)。

VS2012 screenshot for setting

VS2012设置截图

回答by ralphtheninja

Are you using xcopy in your scripts? Thissuggests wrapping xcopy with cmd /c " .. " as a solution.

您在脚本中使用 xcopy 吗?建议用 cmd /c ".." 包装 xcopy 作为解决方案。

If that wasn't it, I'd recommend to narrow things down by only letting one cpu work (i.e. removing /maxcpucount) This would rule out any form of race condition between compilation processes.

如果不是这样,我建议通过只让一个 cpu 工作来缩小范围(即删除 /maxcpucount)这将排除编译过程之间的任何形式的竞争条件。

回答by Joseph Snow

I had a similar problem, but with Visual Studio 2010.

我有一个类似的问题,但使用 Visual Studio 2010。

This is a project that had worked fine on another computer, but just not my new one. The symptoms described matched the original Visual Studio 2008 Issue.

这是一个在另一台计算机上运行良好的项目,但不是我的新计算机。所描述的症状与最初的 Visual Studio 2008 问题相符。

I was able to resolve the issue by installing the Visual Studio 2010 Service Pack 1 (SP1)

我能够通过安装 Visual Studio 2010 Service Pack 1 (SP1) 解决该问题

http://www.microsoft.com/download/en/confirmation.aspx?id=23691- or just go to microsoft and search for "Visual Studio 2010 Service Pack 1"

http://www.microsoft.com/download/en/confirmation.aspx?id=23691- 或者去微软搜索“Visual Studio 2010 Service Pack 1”

I had run my windows "check for updates" and had thought I had installed all service packs, but apparently, I had not installed any Visual Studio Service Packs.

我运行了我的 Windows“检查更新”,并以为我已经安装了所有的服务包,但显然,我没有安装任何 Visual Studio 服务包。

After installing the VS2010 SP1, I no longer had this issue. I confirmed that I had installed VS2010 and the Service Pack 1 on other older computer with the working project a while back.

安装 VS2010 SP1 后,我不再有此问题。我确认我已经在其他较旧的计算机上安装了 VS2010 和 Service Pack 1 以及工作项目。

回答by Ralph

You could try this: Open the build dialog via Menu -> Tools -> Options -> Projects and Solutions -> Build and Run

你可以试试这个:通过菜单 -> 工具 -> 选项 -> 项目和解决方案 -> 构建和运行打开构建对话框

Here you can set "MSBuild project build output verbosity" to "Diagnostic". Maybe this will deliver more information on what is going wrong.

在这里,您可以将“MSBuild 项目构建输出详细程度”设置为“诊断”。也许这会提供更多关于出了什么问题的信息。

In the same dialog you can set "Maximum number of parallel project builds" to 1. Maybe this works around the link.exe "hang".

在同一个对话框中,您可以将“并行项目构建的最大数量”设置为 1。也许这可以解决 link.exe“挂起”的问题。

回答by Sebastiaan M

mspdbsrv.exe is used to combine all debug info into one pdb file. The VS2005 version of mspdbsrv.exe is buggy, it might be that the VS2005 version has some of the same issues. Killing it before building is making a difference for some people. We're going to add it to our builds as well since we're regularly suffering from unknown PDB errors.

mspdbsrv.exe 用于将所有调试信息合并到一个 pdb 文件中。VS2005 版本的 mspdbsrv.exe 有问题,可能是 VS2005 版本有一些相同的问题。在建造之前杀死它对某些人来说会有所不同。我们也将把它添加到我们的构建中,因为我们经常遇到未知的 PDB 错误。

回答by Not Sure

Have you tried disabling incremental linking, or alternatively, always forcing a Rebuild All?

您是否尝试过禁用增量链接,或者始终强制进行全部重建?