Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of msvcr100 over msvcrt

I'd like to ask whether or not there is an advantage in msvcr100 over msvcrt and what would the advantages be.

When compiling with the msvc compiler, the executable I get is linked to msvcr100, so it requires MS Visual C++ Redistributable to be installed. If I compile it with g++ (mingw), then there's no such requirement. I'm guessing it's linked to msvcrt, instead.

I prefer to keep dependencies at a minimum, so I want to know if there's any point in using a compiler that links to mscvr100.

Thank you.

like image 280
user2623040 Avatar asked Feb 15 '23 18:02

user2623040


2 Answers

Msvcrt.dll is a private DLL, intended to be used only by Windows itself. Different versions of Windows have different versions of msvcrt.dll.

You'll have a serious headache when you discover that the way you use the CRT causes failure on a particular Windows version. Including the kind of failure that requires a time machine, a new version of Windows may have a new copy of msvcrt.dll that makes your program fail. A problem otherwise known as DLL Hell.

The advantage of using msvcr100.dll is that the odds for to happen are much smaller. You work with a known version of the CRT. Even if there's a breaking change in Windows itself that breaks msvcr100.dll then there's still a solution: you can update it. That is not possible with msvcr.dll, it is a DLL that's covered by the File System Protection feature. Overwriting it with an installer would normally be pretty disastrous because that can break Windows itself. But it cannot cause failure, Windows automatically restores it. Also the reason you should not follow Voith's advice.

like image 135
Hans Passant Avatar answered Feb 26 '23 16:02

Hans Passant


If you use an MS compiler later than version 6, then you will have to link to the runtime specific to that compiler. You do not have any choice in the matter. Since the MSVC runtimes are not system DLLs, you will need to distribute them with your application.

If you use MSVC6, or a compiler that can link against msvcrt.dll, then you can link against msvcrt.dll.

The mingw compiler is quite configurable. However, I believe that it usually will link against msvcrt.dll. Since msvcrt.dll is a system DLL (since Windows 2000 IIRC) you do not need to distribute it.

I'm assuming in all of this that you link to the runtime dynamically. That is the preferred option, but it is always possible to link to the runtime statically. When you do that, you make your application standalone.

It all boils down to which compiler you prefer to use. If you prefer to use a modern MSVC, then you'll need to accept the runtime distribution, or link statically.

like image 27
David Heffernan Avatar answered Feb 26 '23 18:02

David Heffernan