MS Visual C++运行时库——有什么用?

发布于 2024-10-02 15:38:36 字数 637 浏览 1 评论 0原文

MS Visual C++ 运行时库中有什么?我的意思是,我用谷歌搜索了它,我总是发现像 help, app xxxx 给我 MS Visual C++ 运行时库错误这样的东西,没有任何解释。

我以为Windows C运行时库是Windows自带的?不是用VC++吗?谢谢。

编辑: 首先,感谢您的解答。我现在对 Windows 中的运行时库有不好的了解。我的意思是,第一部分,Windows 内部有它的 win32 API,所以,没关系,我知道。另外,Win32API 来自内核和用户部分。

但我一直认为像 GDI 这样的函数是作为 DLL 访问的(我仍然相信它们是这样的)。但我认为甚至像 printf 这样的函数也在某些 Windows 文件中。

那么,当我知道像 printf 这样的“简单”函数需要直接链接,而不是直接使用操作系统的内核部分,而更复杂的 Windows API 函数作为 dll 链接时,我是对的吗? ,因此不是随编译器发布而是随操作系统发布?他们随后访问内核?

我的意思是,比方说 GDI,我告诉它绘制图片,它在用户模式下完成所有艰苦的工作,然后调用内核函数将其全部放入帧缓冲区中?

最后一个想法,为什么要这样解决?我的意思是,如果 VC++ 运行时只是 C 和 WinAPI 之间的一层,为什么 VC++ 不能直接调用 WinAPI?

What's in MS Visual C++ runtime library? I mean, I googled it, and I always found things like help, app xxxx gives me MS Visual C++ runtime library error, with no explanation.

I thought that Windows C runtime libraries come with Windows? Not with VC++? Thanks.

EDIT:
First, thanks for answers. I thing now I have bad idea of runtime libraries in windows. I mean, the first part, that Windows internally has its win32 API and so, that's OK, I knew it. Also, that Win32API are from kernel and user parts.

But I always thought that functions like GDI are accessed as DLL (which I still believe they are). But I thought even functions like printf and so are in some windows file.

So, am I right, when I know get it that "simple" functions like printf need to be linked directly and than use only Kernel part of OS directly, and more sophisticated Windows API functions are linked as dlls, therefore ARE NOT distributed with compiler but with OS? And they subsequently access Kernel?

I mean, lets say GDI, I tell it to draw picture, it makes all the hard work in user mode and than call kernel function which puts it all in framebuffer?

And last thought, why is this even solved this way? I mean, if VC++ runtime is just layer between C and WinAPI, why cant VC++ call directly WinAPI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我不咬妳我踢妳 2024-10-09 15:38:36

这过于简单化了,但它会给你要点。 MSVCRT 是一组实现部分 C++ 语言的 DLL。 printfmemcpy 等函数都是在这些 DLL 中实现的。

使用特定编译器编译并动态链接到 C++ 运行时的每个程序都必须以某种方式在目标计算机上具有正确版本的 CRT 二进制文件。因此,交付给最终用户的应用程序通常(通常?)也附带有这些 DLL 的包。该软件包称为“可再发行”(或“redist”),并且对于确切的编译器版本和目标平台的每种组合都有一个不同的软件包。例如,以下各项都有单独且不同的重新发布:

  • MSVC 10、64 位窗口
  • MSVC 10、32 位窗口
  • MSVC9、64 位窗口
  • MSVC9 SP1、64 位窗口

等。

是的,Windows 通常“附带”某些版本的 CRT。但是,它附带了运行 Windows 附带的应用程序所需的版本。如果 Windows 及其所有应用程序都是在 MSVC8 SP2 中编译的,而您的应用程序是在 MSVC10 中编译的,则您所需的 CRT 将不会出现在包装盒上,因为它运行的是 Windows。

这就是为什么将应用程序与 redist 一起发布的常见做法。

编辑:

通过像魔术一样的胡迪尼,我预测你的下一个问题将是“我在哪里可以得到redists?”

答案是来自微软。尝试在 Google 上搜索“msvc 9 x64 redist”,您会发现:

http://www.microsoft.com/downloads/en/details.aspx?familyid=bd2a6171-e2d6-4230-b809-9a8d7548c1b6&displaylang=en

This is an oversimplification, but it will give you the gist. The MSVCRT is a set of DLLs that implements parts of the C++ language. Functions like printf, memcpy and the like are implemented in these DLLs.

Every program that is compiled with a particular compiler and dynamically linked to the C++ runtimes must somehow have the correct version of the CRT binaries on the target machine. As a result, applications that ship to end users are often (usually?) also shipped with a package of these DLLs. This package is called a "redistributable" (or "redist"), and there is a different one for every combination of exact compiler version and target platform. For example, there are seperate and distinct redists for each of the following:

  • MSVC 10, 64-bit windows
  • MSVC 10, 32-bit windows
  • MSVC9, 64-bit windows
  • MSVC9 SP1, 64-bit windows

et cetera.

Yes, Windows usually "comes with" some version of the CRT. However, it comes with the version(s) that it needs in order to run the apps that shipped with Windows. If Windows and all it's apps were compiled in MSVC8 SP2 and your app is compiled in MSVC10, the CRT you require won't be present on the box simply because it's running Windows.

This is why its common practice to ship apps along with redists.

EDIT:

By way of Houdini like magic, I predict your next question will be "where do I get the redists?"

The answer is, from MicroSoft. Try a google search for "msvc 9 x64 redist" and you will find:

http://www.microsoft.com/downloads/en/details.aspx?familyid=bd2a6171-e2d6-4230-b809-9a8d7548c1b6&displaylang=en

乖乖哒 2024-10-09 15:38:36

一个简短的答案是,MSVS C/C++ 运行时实现了诸如 malloc/free、stdio、iostream 之类的函数以及一些诸如dynamic_cast 和异常处理之类的 C++ 功能。这些在 Visual Studio 版本之间有所不同,因此不同版本有不同的运行时。

Windows 大多附带 C API(Win32 API),它与 C/C++ 标准库有很大不同。 MSVS C/C++ 运行时调用此 API 来分配内存等。

(我想 Windows 中包含的一些应用程序是用 MSVS 和 C++ 编写的,因此它们确实包含该版本的 MSVS 运行时。

)随着新的 Visual Studio 版本的发布,运行时会发生变化。 Windows 版本的持续时间比这长得多。

A brief answer would be that the MSVS C/C++ runtime implements functions like malloc/free, stdio, iostream and some c++-stuff like dynamic_cast and exception handling. These differs between versions of visual studio, so there are different runtimes for different versions.

Windows ship mostly with a C API (the Win32 API) which rather different from the C/C++ standard library. The MSVS C/C++ runtime calls into this API to allocate memory, etc etc.

(I suppose some of the applications included with Windows are written with MSVS and in C++, so they do include the MSVS runtime for that version.)

Also, the runtime changes as new Visual Studio versions are released. A Windows release lasts much longer than that.

躲猫猫 2024-10-09 15:38:36

使用 Visual C++ 编译的程序需要“运行时” - 这是一些处理应用程序启动/关闭、内存分配/释放、支持读写文件等的代码。

这不是操作系统的一部分,也不是操作系统的一部分最终应用程序的 - 因为所有 C++ 应用程序都可以共享它,所以默认情况下运行时是单独安装的。

此外,Visual C++ 的每个版本都有自己的运行时安装程序,因为每个版本的工作方式都存在细微的差异和改进。对于不同的平台(例如 x86 和 x64),运行时也有不同的版本。

因此,可以从 Microsoft 下载许多“Visual Studio XXXX 运行时安装程序 (YYY)”,其中 XXXX 是 Visual Studio 版本(2005 年、 2008、2010 等),YYY 通常是“x86”或“x64”。

大多数需要运行时的应用程序都会在需要时自动安装它,因此最终用户通常不太了解这些可再发行组件。

Programs compiled with Visual C++ require a "runtime" - this is a bit of code that handles application startup/shutdown, memory allocation/deallocation, support for reading and writing files, etc.

This is not part of the operating system, and not part of the final application - Because all C++ applications can share it, by default the runtime is a separate installation.

In addition, each version of Visual C++ has its own runtime installer, because with each version there are slight differences and improvements in the way all this works. There are also different verisons of the runtime for different platforms (e.g. x86 and x64)

Hence, there are a number of "Visual Studio XXXX runtime installer (YYY)" downloads available from Microsoft, where the XXXX is the visual studio version (2005, 2008, 2010, etc), and YYY is usually "x86" or "x64".

Most applications that need the runtime will automatically install it if needed, so generally end-users are not very aware of these redistributables.

夜空下最亮的亮点 2024-10-09 15:38:36

它们是实现C和C++标准库函数的库。 printf 等标准函数在这些库中实现。

核心 Windows 库仅提供系统调用接口,即 Win32 API,因为这就是您的全部需要构建一个功能齐全的Windows应用程序。 VC++ 库主要是此 API 的包装器,类似于 glibc 库。

例如,C 库中的 malloc 可能会依次使用 VirtualAlloc API 分配内存。

They are the libraries that implement the C and C++ standard library functions. Standard functions such as printf are implemented in these libraries.

The core Windows libraries only provide interfaces to system calls, i.e. the Win32 API, since that is all you need to build a full-featured Windows application. The VC++ libraries are mostly wrappers around this API, and are analogous to the glibc library on Linux.

As an example, malloc from the C library might in turn use the VirtualAlloc API to allocate memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文