5

In Windows, there is a default C library msvcrt.dll.

Is it possible to write simple C programs that uses functions from msvcrt.dll only? That would relieve the need for installing the recent VC runtime.

I think a possible way is to explicitly specify /NODEFAULTLIB, and use the dll import procedure to import msvcrt.dll functions.

Anyone has a clue?

Mr.C64
  • 41,637
  • 14
  • 86
  • 162
stoictopia
  • 183
  • 7
  • @Mr.C64 no need to make that a comment. Everyone interested in changes can see who made them in the edit history. – rubenvb Feb 05 '14 at 16:16
  • 2
    No, it is the private CRT that Windows executables use. You don't have an import library available to link it. Nor does Microsoft have an obligation to solve any problems that can occur when they update it. – Hans Passant Feb 05 '14 at 16:16
  • You don't ever need to install the VC runtime. You might be advised to do so, but you can just link it statically. – David Heffernan Feb 05 '14 at 16:19

2 Answers2

3

You can use MinGW-w64 GCC, which links to msvcrt.dll for exactly the reason you say.

You can find downloads here. You can link your programs with -static-libgcc -static-libstdc++ if you don't want to redistribute any DLLs.

That being said, you can just simply ship the msvcr*.dll files alongside your executable, no need to install anything.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
3

You don't want to use msvcrt.dll.

  • It is very old and therefore doesn't meet modern C run-time library specifications.
  • It exists primarily for backward compatibility and for use by certain system components that have special requirements.
  • You cannot expect that it'll be widely patched if a security problem is discovered.
  • There is no guarantee that a binary made with a modern compiler is going to be compatible with the ABI in msvcrt.dll.
  • Modern C and C++ compilers have intimate knowledge and expectations of their run-time libraries with regard to optimizations, setup, and teardown, so you shouldn't mix and match them.

Use the run-time library that comes with your compiler. You can link to it statically if you don't want to worry about redistributing it, or you can read about the proper ways of redistributing it with your application.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
  • 1
    It is not very old, because there are many modern functions like strcpy_s. – palota Mar 26 '16 at 13:15
  • 1
    Microsoft will certainly patch any security problems in msvcrt.dll because is used by many Windows processes and services. – palota Mar 26 '16 at 13:33
  • 1
    @palota: strcpy_s was introduced in or around 2005, so it's not really that modern. Microsoft will patch a security problem in msvcrt.dll _if_ one of their applications or services would expose the vulnerability. If the vulnerability is exposed only through third-party apps, I wouldn't count on it. – Adrian McCarthy Mar 28 '16 at 18:04