简体   繁体   English

MinGW是如何实现C ++库支持的?

[英]How did MinGW implement C++ Library support?

According to my observation, MinGW use MSVCRT for C, and libstdc++ for C++. 根据我的观察,MinGW使用MSVCRT表示C, libstdc ++表示C ++。

If so, how could they work together? 如果是这样,他们怎么可以一起工作? And, why not uniform C and C++ support, no matter MSVCRT + MSVCPRT or glib + libstdc++ . 而且,无论MSVCRT + MSVCPRT还是glib + libstdc ++ ,为什么不支持统一的C和C ++

I think the mixin between MSVCRT and libstdc++ sounds horrible. 我认为MSVCRTlibstdc ++之间的混音听起来很可怕。 So why did MinGW still choose this? 那为什么MinGW仍然选择这个呢?

Links: 链接:


Below is my observation, just skip it if you could answer the question. 以下是我的观察,如果你能回答这个问题就跳过它。

In order to compile code for native Windows(using only the Win32 API), 为了编译本机Windows的代码(仅使用Win32 API),
MinGW use MSVCRT as the underlying C runtime library(provide Win32 API), MinGW使用MSVCRT作为底层C运行时库(提供Win32 API),
and wirte a bridge layer from scratch in order to connect standard C calls and Win32 API calls. 并从头开始构建桥接层以连接标准C调用和Win32 API调用。

I check C header files in MinGW, stdio.h for example, it has a banner like this. 我在MinGW, stdio.h检查了C头文件,例如,它有一个这样的横幅。

/**
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is part of the mingw-w64 runtime package.
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 */

And inside the file, you will find a lot of _CRTIMP , which means actually it would convert to a Win32 API calls. 在文件中,你会发现很多_CRTIMP ,这意味着它实际上会转换为Win32 API调用。

But for C++ parts, it is quite wired. 但对于C ++部分,它非常有线。
It seems that MinGW use libstdc++ to implement C++ support. 似乎MinGW使用libstdc ++来实现C ++支持。

I check the C++ header files like iostream , it has a banner like this 我检查像iostream这样的C ++头文件,它有这样的横幅

// Standard iostream objects -*- C++ -*-

// Copyright (C) 1997-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

Of course no more _CRTIMP or any MS style symbol. 当然没有_CRTIMP或任何MS风格的符号。
So, MinGW has make libstdc++ works based on MSVCRT! 所以,MinGW让libstdc ++基于MSVCRT工作!

Here is my understanding, please fix me. 这是我的理解, 请修理我。

C Library is means a lot more than C++ Library. C库比C ++库意味着更多。

C Library is the bridge from platform dependent system calls to platform independent C calls . C库是从平台相关system calls到平台无关C calls的桥梁。

C++ Librarys starts from platform independent C calls , then add object-oriented features and make it much easier to use. C ++ Librarys从独立于平台的C calls ,然后添加面向对象的功能并使其更易于使用。

So the reason why not use glibc is much more than the GPL license issue, it is because C Library needs to make system calls and communicate with OS. 因此,不使用glibc的原因远不止GPL许可证问题,而是因为C Library需要进行system calls并与OS进行通信。 So in most case, it comes along with the OS, and will be the only C Library available on the platform. 因此,在大多数情况下,它随操作系统一起提供,并且将成为平台上唯一可用的C库。

Therefore, because C++ library is based on C library, so it is platform independent. 因此,因为C ++库是基于C库的,所以它与平台无关。 So just use the code from libstdc++ and spontaneously it works on Windows. 因此,只需使用libstdc++的代码,并自发地在Windows上运行。 It also explains why libstdc++ could run based on MSVCRT . 它还解释了为什么libstdc++可以基于MSVCRT运行。

Now, things become much easier, because libstdc++ provide better support to latest C++ standard, MinGW choose that. 现在,事情变得更加容易,因为libstdc++为最新的C ++标准提供了更好的支持,MinGW选择了这一点。

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

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