Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omit the msvcr100.dll when developing in C/C++ for windows?

Is it possible to develop in C/C++ for windows and not to link against the msvcr100.dll?

I understand that this is the standard c library for windows, but I was wondering how all the programs on my computer could run if I hadn't Visual Studio or the Redistributable package installed?

like image 200
Erik Avatar asked May 17 '12 12:05

Erik


2 Answers

Right-click your project in the Solution Explorer window, Properties, C/C++, Code Generation, Runtime Library setting. Change it to /MTd. Repeat for the Release configuration, pick /MT

You will now link the static version of the CRT, any functions you use get directly linked into your EXE instead of getting them from msvcr100.dll at runtime. So you no longer have the requirement to deploy the DLL along with your program.

Avoid using this option if you create your own DLLs. It then gets to be important that those DLLs and the EXE use the exact same CRT so they'll all share the same CRT state and the same heap. Because if they don't then you'll have nasty problems with passing C++ objects or pointers that need to be released from one chunk of code to another. An AccessViolation if you are lucky, a memory leak if you are not.

like image 95
Hans Passant Avatar answered Oct 04 '22 20:10

Hans Passant


If you restrict your project to use only C programming language/library, then you can only link against MSVCRT.lib which is completely baked in any Windows version since Windows XP SP3.

It means, that rather than dependency on MSVCR100.DLL (or any other Visual Studio DLL), you can only link against the standard C functions in MSVCRT. By the way, this technique is used in CoApp project developed under umbrella of Microsoft, so I'd consider it as a good pratice in such cases as yours.

Simply, download Windows DDK and link only against $(DDKInstallPath)lib\Crt\$(DDKPlatform)\msvcrt.lib

like image 22
mloskot Avatar answered Oct 04 '22 19:10

mloskot