Visual Studio 2010 MSVCR依赖项删除? [英] Visual Studio 2010 MSVCR dependency removal?

查看:159
本文介绍了Visual Studio 2010 MSVCR依赖项删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过Googleing这个,但我找不到一个解决方案。我试图学习一些基本的C ++。我写了一个简单的hello世界:

I've tried Googleing this but I could not find a solution. I am trying to learn some basic C++. I wrote a simple hello world:

#include <stdio.h>
int main()
{
    printf("hello, world\n");
    return 0;
}

它编译完美,一切!伟大的想,所以我加载我的虚拟机与XP和没有安装服务包,然后试图运行它。它告诉我,我需要MSVCR DLL。有什么办法我可以完全删除这种依赖吗?我不想把程序与DLL。我想让它完全消失。是否有可能制作和运行一个程序,将运行在XP和以上?谢谢。

It compiled perfectly and everything! Great I thought, so I loaded up my virtual machine with XP and no service packs installed, then tried to run it. It told me I needed the MSVCR dll. Is there any way I can completely remove this dependency? I don't want to stuff the program with the dll. I want it to be gone, completely. Is it possible to make and run a program that will run in XP and up? Thanks.

推荐答案

在技术上可以 在C中删除此依赖项,确定它甚至可能在C ++。在任何一种情况下,我不会推荐它。你失去了很多的东西,CRT为你在幕后,你的大多数,你不想要不得不重塑自己在劣等的方式。对于初学者,它是实际调用你的 main 函数以及调用全局和静态C ++对象的构造函数和析构函数的运行时库。

It is technically possible to remove this dependency in C, but I'm not sure it is even possible in C++. And in either case, I would not recommend it. You lose a lot of stuff that the CRT does for you behind the scenes, most of which you don't want to have to reinvent yourself in an inferior fashion. For starters, it's the runtime library that actually calls your main function as well as calling the constructors and destructors for global and static C++ objects.

最好的和最简单的解决方案是改变应用程序如何链接到运行时库。您有两个不同的选项:动态和静态。动态链接更具内存效率,意味着您的应用程序将利用对库进行的任何错误修复。它依赖于运行时DLL的存在为了您的应用程序启动。静态链接实际上在构建的链接阶段将运行时库代码嵌入到应用程序中。这意味着您可以在不分发DLL的情况下运行,但有重要的注意事项。

The best and simplest solution is probably to change how your application links to the runtime libraries. You have two different options: dynamically and statically. Dynamic linking is more memory-efficient and means that your application will take advantage of any bug fixes that are made to the library. It relies on the runtime DLL being present in order for your app to start. Static linking actually embeds the runtime library code into your application during the link phase of the build. This means that you can run without distributing the DLL, but there are important caveats.

对于简单的应用程序,这些注意事项不太可能相关。更改项目选项中使用的链接样式:

For simple apps, it's unlikely that these caveats are relevant. Change the link style in use in your project's options:


  1. 在解决方案资源管理器中右键单击项目名称。

  2. 在左侧树视图中展开C / C ++选项,然后选择代码生成项。

  3. 属性组合框中,选择一个多线程选项。

    调试版本应该使用多线程调试,而发布版本应该使用多线程。

  1. Right-click on your project name in the Solution Explorer.
  2. Expand the "C/C++" option in the left-hand treeview, and select the "Code Generation" item.
  3. In the "Runtime Library" property combobox, choose one of the "Multi-threaded" options.
    Debug builds should use "Multi-threaded Debug", while Release builds should use "Multi-threaded".

请注意,由于您使用的是VS 2010,因此您仍然可以选择动态链接到运行时,并获得这样做的所有优点,而无需运行CRT安装程序目标机器。所有你需要的是可重新分发的DLL放在与应用程序的可执行文件相同的文件夹中。这使得部署(甚至测试)非常简单和直接。你会发现这些库作为Visual Studio安装的一部分:

Do note that since you're using VS 2010, you can still choose to dynamically link to the runtime and gain all of the advantages of doing so without having to run the CRT installer on the target machines. All you need is the redistributable DLL(s) placed into the same folder as your application's executable. This makes deploying (and even testing) very simple and straightforward. You'll find these libraries as part of your Visual Studio installation:

\Program Files\Visual Studio x.0\VC\redist\

当然,调试版本的CRT是从不可再分发的。因为你不应该分发你的应用程序的调试版本,这不是一个问题。确保您已编译了一个发布版本(使用顶部工具栏中的下拉组合框),您将只需要在上述目录中找到的可再发行库。

And of course, the debug versions of the CRT are never redistributable. Since you should not distribute debug versions of your application, this is not a problem. Make sure that you've compiled a "Release" build (using the drop-down combobox in the top toolbar), for which you will require only the redistributable libraries found in the above directory.


我不能使用XP附带的运行时吗?

Can't I use the runtime that comes with XP?

没有C运行时你可以使用任何版本的Windows。 Windows本身确实依赖于C运行时库,但它部署了该库的私有版本供自己使用。应用程序不打算链接到它或以任何方式使用它。你自己是为了部署所有必要的依赖,并且你已经注意到,你不能假设目标机器已经安装了正确的版本。

There is no C runtime for you to use that comes with any version of Windows. Windows itself indeed depends on a C runtime library, but it deploys a private version of that library for its own use. Applications are not intended to link to it or make use of it in any way. You're on your own for deploying all necessary dependencies, and as you've noticed, you cannot assume that the target machines will already have the correct version(s) installed.

这篇关于Visual Studio 2010 MSVCR依赖项删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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