user2214913
user2214913

Reputation: 1511

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

Upvotes: 5

Views: 5655

Answers (2)

Yongwei Wu
Yongwei Wu

Reputation: 5582

  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.

Upvotes: 5

Mats Petersson
Mats Petersson

Reputation: 129374

According to the MS White-paper here:

http://www.microsoft.com/en-gb/download/details.aspx?id=13350

you can redistribute certain parts of the Visual Studio components.

Some software, such as the Microsoft .NET Framework, can be distributed. Components of software products included in MSDN subscriptions that can be distributed (either within an application or as separate files) without royalty are identified in the REDIST.TXT file associated with the product. Components that can be distributed to non-Microsoft platforms are identified in the OTHER-DIST.TXT file associated with the product. Code identified as distributable that has the extension .lib cannot be directly distributed; it must be linked into the application. However, the resulting output can be distributed.

You may also:

  • Modify and distribute source code and objects for code marked as “sample” or “Code Snippet”.
  • Distribute the unmodified output of Microsoft Merge Modules for use with an application's .msi file.
  • Distribute the MDAC_TYP.EXE file containing core data access components (such as the Microsoft SQL Server OLE DB provider and ODBC driver).
  • Distribute the object version of C++ libraries (Microsoft Foundation Classes, Active Template Libraries, and C runtimes).

MS also produces a redistributable package specifically for the purpose of developers: http://www.microsoft.com/en-gb/download/details.aspx?id=40784

So, to answer your questions:

  1. Yes. Although it is "purely C", it contains fundamental functions that are used by the C++ part of C as well, such as file I/O, time and date functions, math functions, and so on.
  2. Within reason. See link above.
  3. No, yes. As described above: You may choose to just say to customers "you need to download an install this package", but the license should allow you to distribute it free of charge with your product.
  4. Depends on what you call "easily" and exactly what parts of the library your code uses. Some functions may be easy to replace, others not so - but it's not easy in the sense of "yes, just go do http://www.example.com/msvcrt.dll-plugin-replacement" - it would require coming up with some replacement code. The reason MinGW DOESN'T come with its own C library is that it's not entirely trivial to write a replacement for ALL of the windows functionality that you may need here...
  5. See above - if it was easy, someone would have done it. There MAY be some compilers out there that come with their own library, but it's probably not a free-of-charge and free to distribute one (I'm not aware of any product that doesn't rely on the MSVCRT.DLL - but it's not impossible that one exists)

Upvotes: 2

Related Questions