为什么我的应用程序需要Visual C ++可再发行组件包 [英] Why does my application require Visual C++ Redistributable package

查看:271
本文介绍了为什么我的应用程序需要Visual C ++可再发行组件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio中编写一个简单的C++应用程序.它还有一个安装项目. 它可以在我的开发计算机上很好地工作,但是当我在用户计算机上安装此应用程序时,它需要Visual C++ Redistributable Package.我想知道为什么我的应用程序需要C++ Redistributable? Windows附带了标准的C++运行时库,不是吗?

I'm writing a simple C++ application in Visual Studio. It also has a setup project. It works well on my development machine, but when I'm installing this application on user's machine it requires Visual C++ Redistributable Package. I'm wondering why does my application require C++ Redistributable? Standard C++ runtime library is shipped with Windows, isn't it?

推荐答案

Microsoft随大多数32位Windows版本提供的C​​运行时库的 only 版本是msvcrt.dll.该库提供了C和C ++程序所需的一组典型的库函数.其中包括字符串操作,内存分配,C风格的输入/输出调用等.

The only version of the C runtime library which is shipped by Microsoft with most of 32 bit Windows versions is msvcrt.dll. This library provides a typical set of library functions required by C and C++ programs. These include string manipulation, memory allocation, C-style input/output calls, etc.

Visual Studio 6.0的编译器与此库链接,因此,如果您在VS 6.0中进行开发,则在大多数用户的计算机上都不会遇到任何问题.

Visual Studio 6.0's compiler links against this library, so if you are developing in VS 6.0 you shouldn't encounter any problems on most users' machines.

但是,如果要在VS 2005,VS 2008,VS 2010,VS 2012,VS 2013或VS 2015中进行开发,则必须随应用程序一起分发其他C运行时库.这是因为它们的编译器分别链接到Windows附带的msvcrt80.dllmsvcrt90.dllmsvcrt100.dllmsvcrt110.dllmsvcrt120.dllmsvcrt140.dll.

However, if you are developing in VS 2005, VS 2008, VS 2010, VS 2012, VS 2013 or VS 2015, you have to distribute additional C runtime libraries along with your application. This is because their compilers link against msvcrt80.dll, msvcrt90.dll, msvcrt100.dll, msvcrt110.dll, msvcrt120.dll and msvcrt140.dll respectively, which are not shipped with Windows.

  1. 可能的解决方案是与运行时库静态链接,但如果应用程序中同时包含.exe.dll,则可能会导致很多问题. 不要这样做.

  1. Possible solution is to link statically with runtime library, but it may cause a lot of problems in case you have both .exe and .dll in your application. Don't do that.

更具体地说,我允许我自己引用答案的一部分:

To be more specific, I'll allow myself to quote a part of this answer:

如果创建DLL和EXE,则使用/MT会有风险.你最终会 在程序中包含多个CRT副本.这尤其是 VS的早期版本存在问题,每个CRT都有自己的CRT 堆,而不是VS2012.但是您仍然可以使用丑陋的运行时 问题,例如,当您有多个"errno"变量时. 强烈建议使用/MD,以免造成此类损失.

Using /MT is risky if you create DLLs as well as an EXE. You'll end up with multiple copies of the CRT in your program. This was especially a problem with earlier versions of VS where each CRT would get its own heap, not so much with VS2012. But you can still have ugly runtime problems when you have more than one "errno" variable for example. Using /MD is highly recommended to avoid such lossage.

  • 另一种可能的解决方案是要求在用户的计算机上安装适当的Microsoft Visual C ++ Redistributable软件包.

  • Another possible solution is to require an appropriate Microsoft Visual C++ Redistributable package to be installed on the user's machine.

    可以通过在设置项目的prerequisites属性中指定此要求来完成.

    It may be done by specifying this requirement in prerequisites property in your setup project.

    此外,您可以通过在安装项目中包含适当的"

    Also, you can distribute the runtime dll by including in your setup project the appropriate "merge module". In this case don't forget to add the appropriate "policy merge module" to avoid errors caused by incorrect runtime version.

    最后,您可以将所需的DLLs放在安装应用程序的同一文件夹中.

    Finally, you can just put required DLLs in the same folder in which your application is installed.

    进一步阅读:

    • "重新分发Visual C ++文件"-MSDN正式文档
    • Further reading:

      • "Redistributing Visual C++ Files" - Official MSDN documentation
      • 这篇关于为什么我的应用程序需要Visual C ++可再发行组件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆