User Tools

Site Tools


Visual Studio

Useful extensions

  • Editor Guidelines: add a line to avoid writing above 80 characters.

Understanding CRT


On windows, even for dynamically library, linking in Visual Studio need a .lib and .dll file.

CRT (C/C++ Runtime Library) define how the standard library is linked against the binary. There are 2 standard library: the one for C, and the one for C++.

It is possible to statically link the standard library to the compiled program using /MT or dynamically using /MD.

Summary of CRT on Windows

  • LIBCPMT.LIB - Multithreaded (Standard C++ Library) /MT
  • LIBCMT.LIB - Multithreaded (C Runtime Library) /MT
  • MSVCPRT.LIB - Multithreaded Dynamically Linked Library w/ MSVCP90.dll (Standard C++ Library) /MD
  • MSVCRT.LIB - Multithreaded Dynamically Linked (C Runtime Library) w/ MSVCR90.dll /MD

Pro/cons of static linking (/MT): - Executable won't depend on a DLL being present on the target system - Executable will be bigger, as it embed the library - If different CRT used , there will be noticeable runtime overhead (different heap allocated for each CRT to keep track of it)

Pro/cons of static linking (/MT): - Can enjoy system updates - Smaller binary - CRT is shared among all DLL

For library development: - Creating static library .lib with /MD is the best bet, as linking with CRT is done during application linking. - Creating a dynamic library .dll with /MD cause the linking to CRT to be done at library linking. Makes the library dependant to the CRT version (and thus the Visual Studio version).

NEVER mix /MD and /MDd, because memory allocation/release is handled differently in debug and release.

visual_studio.txt · Last modified: 2016/10/26 15:32 by louisbob_ext