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

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

问题描述

我正在 Visual Studio 中编写一个简单的 C++ 应用程序.它还有一个安装项目.它在我的开发机器上运行良好,但是当我在用户机器上安装这个应用程序时,它需要 Visual C++ Redistributable Package.我想知道为什么我的应用程序需要 C++ Redistributable?标准 C++ 运行时库随 Windows 一起提供,不是吗?

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 运行时库是 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 运行时库.这是因为他们的编译器链接到 msvcrt80.dllmsvcrt90.dllmsvcrt100.dllmsvcrt110.dllmsvcrt120.dllmsvcrt140.dll,Windows 未附带.

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 都有自己的堆,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.

    可以通过在安装项目的先决条件属性中指定此要求来完成.

    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.

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

    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++ Redistributable 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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