简体   繁体   English

C/C++ 运行时从何而来?

[英]Where does C/C++ runtime come from?

I recently read that C/C++ runtime in windows has 2 parts.我最近读到 windows 中的 C/C++ 运行时有 2 个部分。 First is VC Runtime and other is Universal C Runtime.首先是 VC Runtime,其他是 Universal C Runtime。 As per my reading, Universal C runtime is part of the OS.根据我的阅读,通用 C 运行时是操作系统的一部分。

Question 1: So does it comes with OS installation by default?问题1:那么它是默认自带OS安装的吗? Or has the Universal C Runtime to do something with Windows SDK ie Windows SDK install provides UCRT? Or has the Universal C Runtime to do something with Windows SDK ie Windows SDK install provides UCRT?

Question 2: If the UCRT is part of OS, then what supplies the VC Runtime?问题 2:如果 UCRT 是 OS 的一部分,那么 VC Runtime 由什么提供?

Also, I read that platform toolset provides compiler, linker and standard libraries.另外,我读到平台工具集提供编译器、linker 和标准库。

Question 3: So platform toolset has nothing to do with C/C++ runtime (which is split in 2 parts)?问题 3:那么平台工具集与 C/C++ 运行时无关(分为两部分)? Can we say that platform toolset and C/C++ runtime don't come as single unit on windows OS?我们可以说平台工具集和 C/C++ 运行时在 windows 操作系统上不是作为一个单元出现的吗?

Please clarify.请说清楚。

Universal C runtime comes with the OS on Windows 10 (it's installed when you install the OS).通用 C 运行时随附于 Windows 10 上的操作系统(安装操作系统时已安装)。 On older Windows versions (Vista through 8.1), it is distributed through Windows Update.在较旧的 Windows 版本(Vista 到 8.1)上,它通过 Windows 更新分发。 It can also be locally deployed with your app.它也可以与您的应用一起在本地部署。

If your app supports an OS older than Windows 10, you need to think how you're going to distribute it.如果您的应用支持早于 Windows 10 的操作系统,您需要考虑如何分发它。 You can either include a copy of it with your app (this is the most common solution) or you can require the Windows Update for it to be installed.您可以在您的应用程序中包含它的副本(这是最常见的解决方案),或者您可以要求 Windows 更新才能安装它。

You can read more about it here: https://docs.microsoft.com/en-us/cpp/windows/universal-crt-deployment?view=vs-2019您可以在此处阅读更多相关信息: https://docs.microsoft.com/en-us/cpp/windows/universal-crt-deployment?view=vs-2019

VC Runtime can be supplied in two ways: through Visual C++ redistributable packages installer, or deployed locally with your app. VC 运行时可以通过两种方式提供:通过 Visual C++ 可再发行包安装程序,或使用您的应用程序在本地部署。 If you ship an installer with your app, you can have your installer also install VC Runtime packages.如果您的应用程序附带安装程序,您可以让您的安装程序也安装 VC 运行时包。 If you ship software that doesn't get installed, you will have to drop VC Runtime DLLs next to your application executable.如果您发布的软件未安装,您将不得不将 VC 运行时 DLL 放在您的应用程序可执行文件旁边。 You can read more about deploying with VC Runtime here: https://docs.microsoft.com/en-us/cpp/windows/redistributing-visual-cpp-files?view=vs-2019您可以在此处阅读有关使用 VC 运行时进行部署的更多信息: https://docs.microsoft.com/en-us/cpp/windows/redistributing-visual-cpp-files?view=vs-2019

Also, I read that platform toolset provides compiler, linker and standard libraries.另外,我读到平台工具集提供编译器、linker 和标准库。

This is not entirely correct.这并不完全正确。 It provides standard C++ libraries and runtime (also known as VC Runtime).它提供标准的 C++ 库和运行时(也称为 VC 运行时)。 Standard C libraries and runtime come from Universal C Runtime.标准 C 库和运行时来自通用 C 运行时。

"Universal C Runtime" is, at best, peculiar terminology. “通用 C 运行时”充其量只是一个特殊的术语。

The C compiler comes with a standard library that you link into your code. C 编译器附带一个标准库,您可以将其链接到您的代码中。 The standard library provides all of the functions required by the C standard.标准库提供了 C 标准所需的所有功能。 It's up to the library implementor to figure out how to implement them.由库实现者决定如何实现它们。

The operating system provides services that are useful to programs: memory management, file system, display screen, keyboard input, mouse, whatever.操作系统提供对程序有用的服务:memory 管理、文件系统、显示屏、键盘输入、鼠标等等。 It has its own interface, and code in the standard library uses it as appropriate.它有自己的接口,标准库中的代码酌情使用它。

Different operating systems have different ways of providing these services, so the standard library has to be written differently for different operating systems.不同的操作系统提供这些服务的方式不同,因此标准库必须针对不同的操作系统编写不同的代码。 But calls to the operating system are not necessarily written in C, which is why "Universal C Runtime" isn't really appropriate.但是对操作系统的调用不一定写在 C 中,这就是为什么“通用 C 运行时”不太合适的原因。 For example, back in the olden days of MSDOS, calling the operating system meant setting some values in processor registers and then generating a software interrupt.例如,在过去的 MSDOS 时代,调用操作系统意味着在处理器寄存器中设置一些值,然后生成软件中断。 That's generally not C code, although some runtime libraries provided a code layer so that you could do that without having to write your own assembly code.这通常不是 C 代码,尽管一些运行时库提供了代码层,因此您无需编写自己的汇编代码就可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM