Why do I need a redistributable package on unmanaged code? (msvcp100.dll)
Asked Answered
P

1

20
  1. What is the purpose of the 'msvcrXXX.dll' and 'msvcpXXX.dll'? And what are the differences between msvcr and msvcp?
  2. Why do I need to link them to my binary if it's just a very simple and unmanaged .dll? Is it because it's part of the linker? Why isn't it in the Windows system directory by default as a common library?

I'm just trying to understand why in Windows there are somethings so complicated....

Parthenia answered 21/11, 2011 at 18:22 Comment(0)
F
39

msvcrXXXX.dll is the DLL for the C runtime library. msvcpXXXX.dll is the DLL for the C++ runtime library.

One or both of these dependencies will be added to your binary if you are building using /MD or /MDd, which are the defaults specified by Visual Studio when you create a new C++ project. Using either of these flags indicates that you want your program to link with the DLL version of the C/C++ runtime. You can change the defaults under Project Properties->Configuration Properties->C/C++/Code Generation/Runtime Library.

If you change your project to use /MT or /MTd, then your application will not generate references to either of the DLLs listed above, because the C/C++ runtimes will be linked directly into your program. For most simple programs, this will not cause any problems. However, if your program is broken up into several DLLs that all are built using these flags, then each DLL will maintain a copy of the referenced CRT functions and static data, and you may run into memory allocation/freeing problems. To avoid these, you need to make sure that objects allocated within a given DLL are also freed in that same module.

In general, it is more efficient to use the /MD and /MDd flags for applications that have multiple modules (DLLs), because all of those modules will share a single copy of the C/C++ runtime libraries and their associated data structures within the application process.

For simple, single-module applications, though, feel free to build using /MT or /MTd.

Front answered 21/11, 2011 at 18:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.