33

如果某些应用程序的库动态依赖于 msvcrt.dll,我是否应该使用我的应用程序重新分发 msvcrt.dll 并使用私有 dll?即系统的 msvcrt.dll(dll 地狱)是否可能存在任何不兼容问题?应用程序针对 Windows Server 系统。

4

4 回答 4

33

msvcrt - is a dynamic library for the Microsoft Visual C++ runtime.

There are two options for using the C runtime in Windows:

  1. link with static runtime libs.
    Use either the /MT or the /MTd option to cl.exe. In this case, you will have no dependency on the msvcrt DLL, and therefore you will not have to redistribute it. In Visual Studio, right click on the Project or Solution, Properties > C/C++->Code Generation->Runtime library use Multithreaded and Multithreaded debug respectively. This is the easier way. The downside is that the resulting executable is larger.

  2. link with the dynamic C Runtime library.
    You will use either the /MD or the /MDd option to cl.exe.
    In Visual Studio, right click on the Project or Solution, Properties > C/C++->Code Generation->Runtime library use Multithreaded Dynamic Link and Multithreaded Dynamic Link debug respectively. This results in a smaller EXE, but the downside is that you must install the required MSVCRT when installing your application.


Each release of the VC++ compiler ships with a version of the C runtime (CRT). Visual Studio 2005 shipped with v8 of the compiler, and v8 of the CRT. The actual DLL for v8 was msvcrt80.dll. For VS2008, it was v9, and the dynamic CRT was msvcrt90.dll. But, the CRT is updated and patched more frequently than is the C/C++ compiler. A developer can download an updated CRT, and build against that.

If you compile with the dynamic CRT library, you MUST download a redistributable package for the necessary version of the runtime from microsoft.com and perform a (potentially silent) install of it during your app install.


Prior to VS2005, developers built apps to depend on the MSVCRT that was in the Windows operating system. This would give the benefit of the DLL (small image size) while not incurring the requirement of shipping the CRT DLL in the application install. Prior to Windoes 2000, developers would even install a new MSVCRT.dll in the \Windows installation folder. But, sharing the CRT across many apps and the OS too, turned out to be a really bad idea. With WinXP SP2, the CRT included with Windows changed significantly, and any apps that depended on that version of the CRT were at risk of breaking.

At this point Microsoft tells developers that the MSVCRT.dll that is included with Windows is part of the OS, and may be serviced or patched at any time. It is not supported to build an app against it. Therefore applications should use one of the methods above.

References:

于 2009-07-02T11:11:52.963 回答
26

必须将 msvcrt 与您的应用程序一起提供。它不是操作系统的保证部分。如果某个特定版本的 Windows碰巧拥有它,那只是因为 Windows 中的某些东西正在使用它。

当较新版本的 Windows碰巧不包含人们认为 Windows 附带的二进制文件时,应用程序就崩溃了。当用户选择不安装 WinFax 时,应用程序已经崩溃,这意味着没有安装 msvcrt。

来自雷蒙德陈

根据您运行的 Windows 版本,可能会有各种支持 DLL 用于非正式产品组件但只是随手可用的东西。

...

这个问题今天仍然存在。人们四处搜寻随 Windows 提供的二进制文件,寻找他们可以重新审视的东西。然后当这些二进制文件发生变化或完全消失时,他们会感到惊讶。

来自KB326922 - Visual C++ 中共享 C 运行时组件的重新分发

... CRT DLL 不再被视为系统文件,因此,将 CRT DLL 与任何依赖它的应用程序一起分发。因为它不再是系统组件,所以将它与其他特定于应用程序的代码一起安装在您的应用程序 Program Files 目录中。这可以防止您的应用程序使用可能安装在系统路径上的其他版本的 CRT 库。

如果链接到 MSVCRT ,则必须随应用程序一起提供 msvcrt 。

更多的

决定放弃并将其声明为操作系统 DLL,仅供操作系统组件使用。

尽管MSVCRT.DLL长期以来一直是操作系统 DLL,并且被记录为禁止应用程序使用,但仍有很多人其视为 C 运行时交付通道,这些程序为产品团队。

必须随应用程序重新分发 Microsoft Visual C 运行时,因为 Windows 不附带任何 Microsoft Visual C 运行时。可能碰巧调用了一个 DLL msvcrt.dll不能保证),它不是MSVCRT。

于 2009-07-02T11:46:15.793 回答
12

克里斯的回答不应该被否决,因为两者都是正确的。

问题是有两组不同的 MSVCRT。一套是Visual Studio自带的msvcrt80.dll、msvcrt90.dll等。这是人们通常使用的。正如其他答案所述,它们必须重新分配。

另一个是 System32 文件夹中的 msvcrt.dll(文件名中没有数字),从前一段时间以来,它仅供操作系统本身使用。并且应用程序永远不应该替换/重新安装它。但是,某些应用程序确实链接到它,出于某些原因,例如删除要安装的额外依赖项。但请注意,它不能保证在未来的 Windows 版本中可用。

于 2010-05-07T02:45:11.593 回答
5

msvcrt.dll has become a defacto part of the OS distribution. On windows 98 and 95 and possibly NT4 it was possible to get OS installs without it if one went to care to strip apps like WordPad out of the installation.

Given its ubiquty however, and the fact that since those OSs very few app developers have bothered to ship it, at least since windows 2000 its been an official part of the OS.

Microsoft support has a tool that you can use to double check what products DLLs are shipped with.

Perform a search like this and you can see that msvcrt.dll vsrsion 7.0.3790.0 was part of the Windows server 2003 release.

于 2009-07-02T11:03:48.703 回答