3

I've compiled Hello World with g++ 6.3.0-1 on Eclipse on Windows. The executable doesn't run if it can't find the following dlls:

  • libgcc_s_dw2-1.dll
  • libstdc++-6.dll

Here is the code of my Hello World program:

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!\n"; // prints !!!Hello World!!!
    return 0;
}

As I understand it, MinGW attempts to link against MS's standard dlls whenever possible. Why does it link against its own dlls for something as trivial as iostream? What does iostream require in MinGW's libraries that can't be found in MS' libraries ?

Cutter
  • 1,673
  • 7
  • 27
  • 43
  • Are you using Cygwin? –  Jul 14 '18 at 22:26
  • I'm not using Cygwin. – Cutter Jul 14 '18 at 22:29
  • Possibly https://stackoverflow.com/questions/44488972/static-libstdc-works-on-g-but-not-on-pure-gcc may be helpful. –  Jul 14 '18 at 22:35
  • If you're suggesting static linking, it doesn't really answer my question. My question could be reformulated as "what does require in MinGW's libraries that can't be found in MS' libraries ?" – Cutter Jul 14 '18 at 22:59
  • 1
    Which MS libraries? MinGW on Windows links with the Windows C runtime MSVCRT, but that doesn't support iostrreams. And the iostream library is far from "trivial" - it's one of the most complex libraries in C++. –  Jul 14 '18 at 23:04

1 Answers1

3

<iostream> is certainly not trivial: the standard C++ I/O system itself isn’t too complicated but it uses std::locale and its facets which is reasonably complicated. As such it is built into a shared library. Partly that is done so resulting executables can be shipped as non-open source: libstdc++ is covered by the LGPL which can only be used via a shared object for non-open source programs.

As the I/O and locale subsystem uses a C++ interface and there is no platform C++ ABI using a system implementation isn’t an option. As far as I know, Microsoft doesn’t pubish its C++ ABI and at least at some point in the past it used patented technology to prevent other compilers from targeting it. As a result the C++ ABI used by gcc is incompatible with the MSVC++ one. Note that there is a C ABI defined which can be used.

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380
  • Doesn't "GCC Runtime Library Exception" allow static linking even with closed source? I'm not entirely sure, but [here](https://www.gnu.org/licenses/gcc-exception-3.1-faq.en.html) it says that *"nor the GCC Runtime Library Exception distinguish between static linking, dynamic linking, and other methods for combining code in their conditions. The same permissions are available to you, under the same terms, no matter which method you use."*. – HolyBlackCat Jul 15 '18 at 00:56
  • @HolyBlackCat: interesting. That seems to be a relaxation of what was defined with LGPLv2. Maybe the use a shared object is a left-over from these times. Maybe MINGW also ships with a static version of the library and it would just require suitable linker flags to avoid the need of shared objects. That I don't know: I never used MINGW to build software for Windows. – Dietmar Kühl Jul 15 '18 at 01:04
  • Do you have a reference for the patented technology point as I'd be very interested in reading about it. – Ian Cook Jul 15 '18 at 11:03
  • @IanCook: I have never researched the issue into too much details as it was confirmed by people whom I believe (I attend the C++ committee meetings since a long time and speak to the various C++ compiler developers). Since Windows never was a [primary] target I also wasn't too concerned. Looking at [this answer](https://stackoverflow.com/a/7119896/1120273) seems to imply that the technology in question is relating to structured exceptions. – Dietmar Kühl Jul 15 '18 at 16:22