Microsoft Visual Studio〜C / C ++运行库〜静态/动态链接 [英] Microsoft Visual Studio ~ C/C++ Runtime Library ~ Static/dynamic linking

查看:195
本文介绍了Microsoft Visual Studio〜C / C ++运行库〜静态/动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Microsoft Visual Studio用户。
我的问题是关于C / C ++运行时库。

I am a Microsoft Visual Studio user. My question is about the "C/C++ Runtime Library".

我创建了一个空项目 cpp包含以下代码:

I created an "Empty Project" with a ".cpp" source file "main.cpp" containing the following code:

#include <iostream>

int main(void)
{
    std::cout << "Hello World" << std::endl;
    return 0;
}

iostream是一个头文件,用于输入/编程语言
它是C ++标准库的一部分。

"iostream is a header file which is used for input/output in the C++ programming language. It is part of the C++ standard library."


  1. C ++运行库和C / C ++
    标准库?

  1. Is there a difference between "C/C++ Runtime Library" and "C/C++ Standard Library"?

如何知道C / C ++运行库
库是静态还是动态链接到项目?

How do I know if the "C/C++ Runtime Library" library is statically or dynamically linked to the project?

如何知道这个库在文件系统中的位置?

How do I know where this library is located in the filesystem?

如果C / C ++运行库动态链接到
项目,我如何知道.dll使用和哪里使用的
.dll位于文件系统?

In case, the "C/C++ Runtime Library" is dynamically linked to the project, how can I know which ".dll" is used and where the used ".dll" is located in the filesystem?

假设我将C / C ++运行库静态链接到项目,我可以确保从源代码生成的可执行文件可以工作所有Windows平台(XP / Vista / 7 / ...,32位/ 64位)?

Suppose that I statically link the "C/C++ Runtime Library" to the project, can I be sure that the executable generated from the source code will work on all Windows Platforms (XP/Vista/Seven/..., 32 bit/64 bit)?

将C / C ++ Runtime
Library动态链接到项目的优点/缺点是什么?

What are the advantages/drawbacks of dynamically linking the "C/C++ Runtime Library" to the project?

是否应该将C / C ++ Runtime Libray静态或动态链接到项目?

Should the "C/C++ Runtime Libray" rather be statically or dynamically linked to the project?

感谢您的答案。

推荐答案

C ++ Runtime Library并不意味着什么,它大致是IDE中项目设置的名称。项目+属性,C / C ++,代码生成,运行时库设置。您可以在/ MD和/ MT之间选择。

The term "C/C++ Runtime Library" doesn't mean anything, it is roughly the name of a project setting in the IDE. Project + Properties, C/C++, Code Generation, Runtime Library setting. There you can choose between /MD and /MT.

使用/ MD,默认设置,您的程序将使用DLL版本的运行时库。在您的机器上,他们被Visual Studio安装程序复制到c:\windows \system32和/或c:\windows \syswow64。你有它们的副本在VS安装目录的vc / redist子目录中,您可以在为程序创建安装程序时使用。它们的三个版本,32位Intel处理器的x86,64位Intel处理器的x64,ARM处理器的arm。根据您在项目中选择的平台选择正确的一个。

With /MD, the default setting, your program will be using the DLL version of the runtime libraries. On your machine they were copied into c:\windows\system32 and/or c:\windows\syswow64 by the Visual Studio installer. And you've got copies of them in the vc/redist subdirectory of the VS install directory, there for you to use when you create an installer for your program. Three versions of them, x86 for 32-bit Intel processors, x64 for 64-bit Intel processors and arm for ARM processors. Pick the right one based on the Platform you selected in your project.

相关的DLL名称是:


  • msvcr110.dll:C运行库(memcpy等)

  • msvcp110.dll:C ++标准库(std :: string等)

  • vccorlib110.dll:Windows应用商店应用的运行时库

  • vcomp110.dll:OpenMP的运行时库(参见#pragma omp)

  • atl110.dll:ATL项目的运行时库

  • mfc110 * .dll:MFC项目的运行时和本地化库

  • vcamp110.dll:AMP项目的运行时库

  • msvcr110.dll : the C runtime library (memcpy et al)
  • msvcp110.dll : the C++ standard library (std::string et al)
  • vccorlib110.dll : the runtime library for Windows Store applications
  • vcomp110.dll : the runtime library for OpenMP (see #pragma omp)
  • atl110.dll : the runtime library for ATL projects
  • mfc110*.dll : runtime and localization libraries for MFC projects
  • vcamp110.dll : the runtime library for AMP projects

在您的机器上,还有这些DLL的调试版本到VS安装程序到Windows目录。它们具有相同的名称,并带有字母d。仅用于调试您的代码,您不能重新分发它们。相应的运行时库设置为/ MDd。

On your machine, you've also got the debug builds of those DLLs, copied to the Windows directory by the VS installer. They have the same name with the letter "d" appended. Useful only to debug your code, you can't redistribute them. The corresponding Runtime Library setting is /MDd.

大多数C ++项目只需要msvcr110.dll和msvcp110.dll,你会知道什么时候选择使用其他库因为它们有特定的项目模板和设置。

Most C++ projects only need msvcr110.dll and msvcp110.dll, you'd know when you opt in to use the other libraries since there are specific project templates and settings for them.

一个简单的方法来获取所有这些DLL安装在用户的机器上是使用预构建的安装程序。您可以从从这里下载(注意:目前只有今天,这个可能在服务包或更新可用时更改)。或者您可以简单地将它们复制到与主EXE相同的目录中。

A simple way to get all of these DLLs installed on your user's machine is to use the prebuilt installer. You can download it from here (note: current only as of today, this may change when a service pack or update becomes available). Or you can simply copy them into the same directory as your main EXE.

通过将运行库设置更改为/ MT,可以避免对这些DLL的依赖。在这种情况下,运行时支持代码链接到您的程序,您将只有一个EXE要部署。

You can avoid taking a dependency on these DLLs by changing the Runtime Library setting to /MT. In which case the runtime support code is linked into your program and you'll have only a single EXE to deploy. It will of course get bigger when you do so, sometimes significantly so, especially when you use MFC.

使用/ MT是危险的,如果你创建DLL以及一个EXE 。你最终会在你的程序中有多个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.

您的程序将在Windows Vista,7和8上运行。支持XP正在减弱, 1并将项目中的工具集设置从v110更改为v110_xp,以创建仍在XP上运行的程序。某些功能在这样做时会丢失,与区域设置和线程本地存储相关联,需要进行测试。

Your program will run on Windows Vista, 7 and 8. Support for XP is waning, you'll need VS Update 1 and change the toolset setting in the project from "v110" to "v110_xp" to create a program that still runs on XP. Some functionality is lost when you do so, associated with locale and thread-local storage, testing is required.

这篇关于Microsoft Visual Studio〜C / C ++运行库〜静态/动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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