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

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

问题描述

我尝试过Google,但找不到解决方案。我正在尝试学习一些基本的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加载了我的虚拟机,没有安装Service Pack,然后尝试运行它。它告诉我,我需要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天全站免登陆