C++ 当我在一台机器上开发一个 EXE 并在另一台机器上运行它时,为什么安装 vcredist_x86.exe 不能修复 SideBySide 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8913543/
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-08-28 19:18:21  来源:igfitidea点击:

Why installing vcredist_x86.exe doesn't fix SideBySide error when I develop an EXE on one machine and run it on another one?

c++visual-c++side-by-side

提问by Susam Pal

Issue

问题

I wrote a C++ project called 'Foo' using Microsoft Visual Studio 2005 Verison 8.0.50727.762 (SP.050727-7600) on Windows XP Professional Version 2002 Service Pack 3. I built the project into Foo.exe. Then, I copied the file Foo.exe to a Windows Server 2003 Enterprise Edition Service Pack 2. When I tried to run it, it failed with this error,

我在 Windows XP Professional Version 2002 Service Pack 3 上使用 Microsoft Visual Studio 2005 Verison 8.0.50727.762 (SP.050727-7600) 编写了一个名为“Foo”的 C++ 项目。我将该项目构建到 Foo.exe 中。然后,我将文件 Foo.exe 复制到 Windows Server 2003 Enterprise Edition Service Pack 2。当我尝试运行它时,它失败并出现此错误,

C:\foo.exe
The application has failed to start because the application configuration is incorrect.
Reinstalling the application may fix the problem.

In Event Viewer > System, three events were logged.

在事件查看器 > 系统中,记录了三个事件。

Event ID: 32; Source: SideBySide

事件 ID:32;来源:SideBySide

Dependent Assembly Microsoft.VC80.CRT could not be found and Last Error was
The referenced assembly is not installed on your system.

Event ID: 59; Source: SideBySide

事件 ID:59;来源:SideBySide

Resolve Partial Assembly failed for Microsoft.VC80.CRT.
Reference error message: The referenced assembly is not installed on your system.

Event ID: 59; Source: SideBySide

事件 ID:59;来源:SideBySide

Generate Activation Context failed for C:\foo\Foo.exe.
Reference error message: The referenced assembly is not installed on your system.

Installing Microsoft Visual C++ 2005 Redistributable didn't fix it

安装 Microsoft Visual C++ 2005 Redistributable 并没有修复它

  1. Downloaded vcredist_x86.exe from http://www.microsoft.com/download/en/details.aspx?id=3387
  2. Installed it. The installer created a folder called C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd.
  1. http://www.microsoft.com/download/en/details.aspx?id=3387下载 vcredist_x86.exe
  2. 安装了它。安装程序创建了一个名为C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd.

The version of this software as found from 'Add or Remove Programs' was '8.0.50727.42'.

从“添加或删除程序”中找到的该软件版本为“8.0.50727.42”。

On trying to run C:\foo\foo.exe, I got the same errors I described above.

在尝试运行 C:\foo\foo.exe 时,我遇到了与上述相同的错误。

Installing Microsoft Visual C++ 2005 SP1 Redistributable didn't fix it

安装 Microsoft Visual C++ 2005 SP1 Redistributable 并没有修复它

  1. Downloaded vcredist_x86.exe from http://www.microsoft.com/download/en/details.aspx?id=5638
  2. Installed it. The installer created a folder called: C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700.
  1. http://www.microsoft.com/download/en/details.aspx?id=5638下载 vcredist_x86.exe
  2. 安装了它。安装程序创建了一个名为:的文件夹C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700

The version of this software as found from 'Add or Remove Programs' was '8.0.56336'.

从“添加或删除程序”中找到的该软件版本为“8.0.56336”。

On trying to run C:\foo\foo.exe, I got the same errors I described above.

在尝试运行 C:\foo\foo.exe 时,我遇到了与上述相同的错误。

Copying CRT DLLs and manifest from the same machine (where I'm running the EXE) didn't fix it.

从同一台机器(我运行 EXE 的地方)复制 CRT DLL 和清单并没有修复它。

  1. I copied msvcm80.dll, msvcp80.dlland msvcr80.dllfrom C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acdto C:\foo.
  2. Next, I copied C:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd.manifestto C:\fooand renamed it to Microsoft.VC80.CRT.manifest.
  1. 我复制msvcm80.dllmsvcp80.dllmsvcr80.dllC:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acdC:\foo
  2. 接下来,我复制 C:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd.manifestC:\foo它改名为Microsoft.VC80.CRT.manifest

The fourth line of the manifest file looked like this:

清单文件的第四行如下所示:

<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50727.42"
                  processorArchitecture="x86"
                  publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>

When I tried running C:\foo\foo.exe this time, it didn't work. I repeated this thing again with the DLLs in C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700and the corresponding manifest file. It didn't help as well. I got the same error.

这次当我尝试运行 C:\foo\foo.exe 时,它​​不起作用。我用 DLLC:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700和相应的清单文件再次重复了这件事。它也没有帮助。我得到了同样的错误。

In both cases, I got the following errors in Event Viewer > System.

在这两种情况下,我都在事件查看器 > 系统中收到以下错误。

Event ID: 34; Source: SideBySide

事件 ID:34;来源:SideBySide

Component identity found in manifest does not match the identity of the component requested

Event ID: 58; Source: SideBySide

事件 ID:58;来源:SideBySide

Syntax error in manifest or policy file "C:\foo\Microsoft.VC80.CRT.MANIFEST" on line 4.

Event ID: 59; Source: SideBySide

事件 ID:59;来源:SideBySide

Generate Activation Context failed for C:\foo\Foo.exe. Reference error message: The manifest file contains one or more syntax errors.

Copying CRT DLLs and manifest from the Windows XP machine (where I built the EXE) didn't fix it.

从 Windows XP 机器(我在其中构建 EXE)复制 CRT DLL 和清单并没有修复它。

  1. I copied msvcm80.dll, msvcp80.dlland msvcr80.dllfrom C:\winnt\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700of Windows XP machine (where I developed and built foo.exe) to C:\fooof Windows Server 2003 (where I am trying to run foo.exe).
  2. Next, I copied C:\winnt\winsxs\Manifests\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700.manifestto C:\fooand renamed it to Microsoft.VC80.CRT.manifest.
  1. 我复制msvcm80.dllmsvcp80.dll以及msvcr80.dllC:\winnt\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700Windows XP计算机(其中我公司开发和制造foo.exe的),以C:\foo在Windows Server 2003(其中我试图运行foo.exe的)的。
  2. 接下来,我复制 C:\winnt\winsxs\Manifests\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700.manifestC:\foo它改名为Microsoft.VC80.CRT.manifest

The fourth line of the manifest file looked like this:

清单文件的第四行如下所示:

<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50727.762"
                  processorArchitecture="x86"
                  publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>

On trying to run C:\foo\foo.exe now I got the same errors mentioned in the previous section.

现在尝试运行 C:\foo\foo.exe 时,我遇到了上一节中提到的相同错误。

Copying CRT DLLs and manifest from Visual Studio folder fixed it.

从 Visual Studio 文件夹复制 CRT DLL 和清单修复了它。

  1. Copied msvcm80.dll, msvcp80.dll, msvcr80.dlland Microsoft.VC80.CRT.manifestfrom C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRTof Windows XP machine (where I developed and built foo.exe) to C:\fooof Windows Server 2003 machine (where I am trying to run it).
  1. 复制msvcm80.dllmsvcp80.dllmsvcr80.dll以及Microsoft.VC80.CRT.manifestC:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRTWindows XP计算机(其中我公司开发和制造foo.exe的)到C:\fooWindows Server 2003的计算机(其中我试图运行它)。

The fourth line of the manifest file looked like this:

清单文件的第四行如下所示:

<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50727.6195"
                  processorArchitecture="x86"
                  publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>

This time I could run C:\foo\foo.exe without any issues.

这次我可以毫无问题地运行 C:\foo\foo.exe。

Question

I was expecting that installing 'Microsoft Visual C++ 2005 SP1 Redistributable' (vcredist_x86.exe) as described in the second approach would fix it. But it didn't. Copying the DLLs and manifest files from the C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRTfolder of the development machine fixed it. Why was it so?

我期待安装“Microsoft Visual C++ 2005 SP1 Redistributable”(vcredist_x86.exe),如第二种方法所述会修复它。但它没有。从C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT开发机器的文件夹中复制 DLL 和清单文件修复了它。为什么会这样?

Build options

构建选项

In case, it helps you to answer my question. Here is the compiler and linker options I picked up from Visual Studio project properties:

以防万一,它可以帮助您回答我的问题。这是我从 Visual Studio 项目属性中选取的编译器和链接器选项:

Configuration properties > C/C++ > Command Line:

配置属性 > C/C++ > 命令行:

/O2 /GL /D "_MBCS" /FD /EHsc /MD /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt

/O2 /GL /D "_MBCS" /FD /EHsc /MD /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt

Configuration properties > Linker > Command Line:

配置属性 > 链接器 > 命令行:

/OUT:"C:\MixedBag\Release\Foo.exe" /NOLOGO /MANIFEST /MANIFESTFILE:"Release\Foo.exe.intermediate.manifest" /DEBUG /PDB:"c:\MixedBag\release\Foo.pdb" /OPT:REF /OPT:ICF /LTCG /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

/OUT:"C:\MixedBag\Release\Foo.exe" /NOLOGO /MANIFEST /MANIFESTFILE:"Release\Foo.exe.intermediate.manifest" /DEBUG /PDB:"c:\MixedBag\release\Foo.pdb" /OPT:REF /OPT:ICF /LTCG /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

回答by Susam Pal

I'll answer my own question. Comments to the question by Hans Passant and Luke helped.

我会回答我自己的问题。Hans Passant 和 Luke 对问题的评论有所帮助。

I downloaded Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC Security Updateand installed it on the system where I was trying to run C:\foo\foo.exe. The EXE ran fine after this.

我下载了Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC 安全更新并将其安装在我试图运行C:\foo\foo.exe. 在此之后,EXE 运行良好。

The installer placed the CRT DLLs in C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86. So, yes, 8.0.50727.6195 was the version of the CRT DLLs I was looking for as Hans Passant rightly said.

安装程序将 CRT DLL 放在C:\windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86. 所以,是的,8.0.50727.6195 是我正在寻找的 CRT DLL 版本,正如 Hans Passant 所说的那样。

The easiest way to figure this version was by looking at the manifest file generated by Visual Studio while building my project on the development system. Mine was located at C:\Foo\Release\Foo.exe.intermediate.manifest. It had a tag like this:

确定此版本的最简单方法是在开发系统上构建我的项目时查看 Visual Studio 生成的清单文件。我的位于C:\Foo\Release\Foo.exe.intermediate.manifest。它有一个这样的标签:

<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.6195'
                  processorArchitecture='x86'
                  publicKeyToken='1fc8b3b9a1e18e3b' />

So, this is a clue that I needed 8.0.50727.6195 version of the DLLs. The rest was a matter of searching for the right vcredist_x86.exe which happened to be in the URL I have mentioned in the second paragraph. The page in that URL contains a link to KB2538242which shows the version numbers of the DLLs that would be installed by the installer.

所以,这是我需要 8.0.50727.6195 版本的 DLL 的线索。剩下的就是搜索正确的 vcredist_x86.exe,它恰好在我在第二段中提到的 URL 中。该 URL 中的页面包含指向KB2538242的链接,该链接显示将由安装程序安装的 DLL 的版本号。

Note: As Elie has mentioned in a different answerto this question, since this is a 32-bit application, it is necessary to install vcredist_x86.exe (not vcredist_x64.exe) on the system where this application is supposed to be run irrespective of whether that system is a 32-bit Windows system or a 64-bit Windows system. Once again, the .manifest file provides this clue in the processorArchitectureattribute.

注意:正如 Elie 在这个问题的不同答案中提到的,由于这是一个 32 位应用程序,因此有必要在该应用程序应该运行的系统上安装 vcredist_x86.exe(而不是 vcredist_x64.exe),而不管它是什么该系统是 32 位 Windows 系统还是 64 位 Windows 系统。再一次,.manifest 文件在processorArchitecture属性中提供了这个线索。

回答by Elie

Here is how you fix this issue:

以下是您解决此问题的方法:

You WILLSTILL Get the sidebyside errors If the application being used is 32 bit and you try running it on a 64 bit OS which has the VC_REDISTx64 installed.

WILL仍然得到sidebyside错误如果正在使用的应用程序是32位,并尝试在其上安装了一个VC_REDISTx64 64位操作系统上运行它。

Simple solution, you MUST ALSO LOAD THE VC_REDISTx86 on the 64 bit os

简单的解决方案,您还必须在 64 位操作系统上加载 VC_REDISTx86

回答by Weisheng Liu

You have to install "Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC Security Update" which is here: http://www.microsoft.com/en-us/download/details.aspx?id=26347

您必须在此处安装“Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC 安全更新”:http: //www.microsoft.com/en-us/download/details.aspx?id=26347

回答by user1752563

I had a somewhat related problem. Two development XP machines with VS2005 installed, call them A and B. I developed, built and ran on A. Then I copied the whole project to B. Built there. Tried to run and got the same error messages mentioned by SusamPal. I realized that on B's WinSxS there were the x86_Microsoft.VC80.CRT_xxx manifests (and folders) but not the corresponding x86_Microsoft.VC80.DebugCRT_xxx ones (and why?!). I tried several of the dances and incantations described by SusamPal to no avail. I solved the problem by copying the appropriate folders from the WinSxS of A to B AND the appropriate manifests from the WinSxs\Manifests.

我有一个有点相关的问题。安装了 VS2005 的两台开发 XP 机器,分别称为 A 和 B。我在 A 上开发、构建和运行。然后我将整个项目复制到 B。在那里构建。尝试运行并收到 SusamPal 提到的相同错误消息。我意识到在 B 的 WinSxS 上有 x86_Microsoft.VC80.CRT_xxx 清单(和文件夹),但没有相应的 x86_Microsoft.VC80.DebugCRT_xxx 清单(为什么?!)。我尝试了 SusamPal 描述的几种舞蹈和咒语,但无济于事。我通过将 A 的 WinSxS 中的适当文件夹复制到 B 以及 WinSxs\Manifests 中的适当清单来解决该问题。

回答by superlee

Although my application was

虽然我的申请是

developedon Win 2k8 R2 x64 with vs2008 (which has msvcm90.dll, msvcp90.dll and msvcr90.dll in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\amd64\Microsoft.VC90.CRT)

使用 vs2008 在 Win 2k8 R2 x64 上开发(在 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\amd64\Microsoft.VC90.CRT 中有 msvcm90.dll、msvcp90.dll 和 msvcr90.dll)

and ranon win 2k3 SP2 x64,

RAN上取胜2K3 SP2 64位,

but the msvcm80.dll, msvcp80.dll and msvcr80.dll are needed.

但需要 msvcm80.dll、msvcp80.dll 和 msvcr80.dll。

After install Microsoft Visual C++ 2005 SP1 Redistributable Package (x86), the application can be installed and ran rightly.

安装Microsoft Visual C++ 2005 SP1 Redistributable Package (x86) 后,可以正确安装和运行该应用程序。

回答by shivi

For me the side by side error went just by chabging the under the setting c/c++ ->CodeGeneration->RuntimeLibrary ,make it MTD that is multi-Thread Debug

对我来说,并排错误只是通过设置 c/c++ ->CodeGeneration->RuntimeLibrary 下的设置,使其成为多线程调试的 MTD

回答by user5058117

We have really following problem here: the application executable references dlls using manifest machinery. In the deep past application authors just copied required dll's into system directories. Unfortunately this caused so called "dll hell" problem when overwriting older dll versions by incompatible newer one could make applications stop working. MS then came up with with versioning idea (winsxs).

我们在这里确实存在以下问题:应用程序可执行文件使用清单机制引用 dll。在过去,应用程序作者只是将所需的 dll 复制到系统目录中。不幸的是,当用不兼容的较新版本覆盖旧 dll 版本可能会使应用程序停止工作时,这会导致所谓的“dll 地狱”问题。MS 然后想出了版本控制的想法(winsxs)。

Unfortunately this is quite complex machinery and it is definitely not a good idea to try manually installing dlls (assemblies) into the sxs folder. Installing so called "redistributable packages" is not a perfect solution either.

不幸的是,这是相当复杂的机器,尝试将 dll(程序集)手动安装到 sxs 文件夹中绝对不是一个好主意。安装所谓的“可再发行包”也不是一个完美的解决方案。

Additionally, this cannot help when we want debug versions. As MS prohibits distribution of debug versions of supporting dlls, "redistributable packages" won't install them. (Note that the assembly id depends on current subversion of VS2005 and is related to installed supporting libraries.)

此外,当我们需要调试版本时,这无济于事。由于 MS 禁止分发支持 dll 的调试版本,“可再分发包”不会安装它们。(请注意,程序集 ID 取决于 VS2005 的当前 subversion,并且与已安装的支持库相关。)

Usually, the VS installer adds the required assemblies to the system, but after some time installation of updates or newer SDK's and tools may damage this correct state.

通常,VS 安装程序会将所需的程序集添加到系统中,但一段时间后安装更新或更新的 SDK 和工具可能会破坏此正确状态。

Let's assume we have this situation - our debug libraries are no longer integrated into system. Suppose we have given workspace with project A and active debug configuration giving not working application. We can then create installer project, say C in current workspace, add our application (or strictly, project with active configuration) to it. Setup installer project to put our executable in some place (desktop is the right place regarding this situation) enable dependencies check and some other minor properties. Then build project C and run installer (or "install" from VS using context menu). Now your application and other created with debug dll libraries start to work.

让我们假设我们有这种情况 - 我们的调试库不再集成到系统中。假设我们已经为项目 A 提供了工作区,并提供了不工作的应用程序的活动调试配置。然后我们可以创建安装程序项目,例如在当前工作区中的 C,将我们的应用程序(或严格来说,具有活动配置的项目)添加到其中。设置安装程序项目以将我们的可执行文件放在某个位置(桌面是这种情况的正确位置)启用依赖项检查和其他一些次要属性。然后构建项目 C 并运行安装程序(或使用上下文菜单从 VS 中“安装”)。现在您的应用程序和其他使用调试 dll 库创建的应用程序开始工作。

Beware when you run installer with "remove" option you came to previous situation. Here is good article related to distribution topic: http://blogs.msdn.com/b/vcblog/archive/2007/10/12/how-to-redistribute-the-visual-c-libraries-with-your-application.aspx.

请注意,当您使用“删除”选项运行安装程序时,您会遇到以前的情况。这是与分发主题相关的好文章:http: //blogs.msdn.com/b/vcblog/archive/2007/10/12/how-to-redistribute-the-visual-c-libraries-with-your-application .aspx

If you have some other applications and want to deploy them simply by copying, maybe on non development machine without installed VS, you may create dummy project together with appropriate configuration and installer for it . You then install it once on each machine and then copy executable(s) you are working on.

如果您有一些其他应用程序并且想通过复制来部署它们,也许在没有安装 VS 的非开发机器上,您可以创建虚拟项目以及适当的配置和安装程序。然后在每台机器上安装一次,然后复制您正在处理的可执行文件。