Search code examples
windowslinkermingwmingw-w64msvcrt

MinGW / MinGW64 Linking and Dependency on `msvcrt.dll`


I am coding for WinAPI in MinGW

One thing I still have not fully understood is the VC redistributable, I got a whole pack of question to it

Some say that such programs will need the msvcrt.dll

  1. is the same library needed for bot c++ and c compilation?
  2. is this available on all targets of clients?
  3. must I redistribute it? can I redistribute it?
  4. can I easily get rid of this external dependency?
  5. is there other compiler that will allow me not to carry such unpleasant external dependency? (as I vaguely remember hearing that something is wrong with it - it is probably not core system lib, I heard, or it is not free to use and redistribute the library)

I see something wrong is here as I would like to produce no dependency small exes only calling the system WinAPI and if I use some like C standard library functions functions I would prefer it economically and statically compiled in, not any third-party dependencies


Solution

    1. MSVCRT.DLL contains mostly the C runtime, and MinGW can only use the C part. C++ binary code cannot be used across compilers generally.
    2. It depends on your "target". It is available from Windows 2000.
    3. No. No. It is Microsoft-proprietary code, and every Windows version has a slightly different version.
    4. No. I am not aware of a mature alternative C run-time DLL.
    5. You do not need to worry about the dependency, as it is available everywhere. (Do notice that it is not really a great run-time, esp. regarding multi-byte characters.)

    Microsoft compilers can link with "static" libraries so that the resulting executable depends only on system DLLs like kernel32.dll, user32.dll, etc. MinGW cannot do this (yet).

    EDIT: A concise description of the MSVCRT.DLL problem is here.