【发布时间】:2015-01-15 05:33:46
【问题描述】:
根据我的观察,MinGW 对 C 使用 MSVCRT,对 C++ 使用 libstdc++。
如果是这样,他们怎么能一起工作?而且,为什么不统一 C 和 C++ 支持,无论是 MSVCRT + MSVCPRT 还是 glib + libstdc++。 p>
我认为 MSVCRT 和 libstdc++ 之间的混合听起来很可怕。那为什么MinGW还是选择这个呢?
链接:
- C99 | MinGW
- MinGW | MinGW
- CRT Library Features
- Description of the default C and C++ libraries that a program will link with when built by using Visual C++
以下是我的观察,如果你能回答问题,请跳过它。
为了编译原生 Windows 的代码(仅使用 Win32 API),
MinGW使用MSVCRT作为底层C运行库(提供Win32 API),
并从头开始编写一个桥接层,以便连接标准 C 调用和 Win32 API 调用。
我在 MinGW 中检查 C 头文件,例如stdio.h,它有这样的横幅。
/**
* 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.
*/
在文件中,你会发现很多_CRTIMP,这意味着它实际上会转换为Win32 API调用。
但是对于 C++ 部分,它是相当连贯的。
似乎 MinGW 使用 libstdc++ 来实现 C++ 支持。
我检查了像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.
当然不再有 _CRTIMP 或任何 MS 风格的符号。
所以,MinGW 已经让 libstdc++ 基于 MSVCRT 工作了!
【问题讨论】:
-
因为 C 库中充满了系统调用包装器,并且这些系统调用依赖于 Linux/Hurd。另一方面,C++ 库几乎是用户空间的东西(模
支持),并且可以存在于任何合理的 C 库 之上 -
@SeverinPappadeux 你提醒我了!我什至忘记了这样一个基本事实。
-
gcc 不太可能兼容
msvcprt.dll。 -
@SeverinPappadeux:这对我来说像是一个答案!
标签: c++ windows mingw libstdc++ msvcrt