Export (0) Print
Expand All
18 out of 36 rated this helpful - Rate this topic

C Run-Time Libraries

This topic discusses the various .lib files that comprise the C run-time libraries as well as their associated compiler options and preprocessor directives.

The following libraries contain the C run-time library functions.

C run-time library (without iostream or standard C++ library) Characteristics Option Preprocessor directives
LIBC.LIB Single-threaded, static link /ML  
LIBCMT.LIB Multithreaded, static link /MT _MT
MSVCRT.LIB Multithreaded, dynamic link (import library for MSVCR71.DLL). Be aware that if you use the Standard C++ Library, your program will need MSVCP71.DLL to run. /MD _MT, _DLL
LIBCD.LIB Single-threaded, static link (debug) /MLd _DEBUG
LIBCMTD.LIB Multithreaded, static link (debug) /MTd _DEBUG, _MT
MSVCRTD.LIB Multithreaded, dynamic link (import library for MSVCR71D.DLL) (debug) /MDd _DEBUG, _MT, _DLL

If you link your program from the command line without a compiler option that specifies a C run-time library, the linker will use LIBC.LIB.

To build a debug version of your application, the _DEBUG flag must be defined and the application must be linked with a debug version of one of these libraries. For more information about using the debug versions of the library files, see CRT Debugging Techniques.

This version of Visual C++ is not conformant with the C99 standard.

Standard C++ Library

Note that starting in Visual Studio .NET 2003, Visual C++ will no longer ship the old iostream libraries. For details, see Upgrade to the Standard C++ Library and the Standard C++ Library Overview.

The new iostream functions, as well as many other new functions, exist in the Standard C++ Library:

Standard C++ Library Characteristics Option Preprocessor directives
LIBCP.LIB Single-threaded, static link /ML  
LIBCPMT.LIB Multithreaded, static link /MT _MT
MSVCPRT.LIB Multithreaded, dynamic link (import library for MSVCP71.dll) /MD _MT, _DLL
LIBCPD.LIB Single-threaded, static link /MLd _DEBUG
LIBCPMTD.LIB Multithreaded, static link /MTd _DEBUG, _MT
MSVCPRTD.LIB Multithreaded, dynamic link (import library for MSVCP71D.DLL) /MDd _DEBUG, _MT, _DLL

When you build a release version of your project, one of the basic C run-time libraries (LIBC.LIB, LIBCMT.LIB, and MSVCRT.LIB) is linked by default, depending on the compiler option you choose (single-threaded, multithreaded, or DLL). If you include a Standard C++ Library header in your code, a Standard C++ Library will be linked in automatically by Visual C++ at compile time. For example:

#include <ios> 

What is the difference between msvcrt.dll and msvcr71.dll?

The msvcrt.dll is now a "known DLL," meaning that it is a system component owned and built by Windows. It is intended for future use only by system-level components. An application should use and redistribute msvcr71.dll, and it should avoid placing a copy or using an existing copy of msvcr71.dll in the system directory. Instead, the application should keep a copy of msvcr71.dll in its application directory with the program executable. Any application built with Visual C++ .NET using the /MD switch will necessarily use msvcr71.dll.

What problems exist if an application uses both msvcrt.dll and msvcr71.dll?

If you have a .lib or .obj file that needs to link to msvcrt.lib, then you should not have to recompile it to work with the new msvcrt.lib in Visual C++ .NET. The .lib or .obj file may rely on the sizes, field offsets, or member function names of various CRT classes or variables, and those should all still exist in a compatible way. When you relink against msvcrt.lib, your final EXE and DLL image will now have a dependency on msvcr71.dll instead of msvcrt.dll.

If you have more than one DLL or EXE, then you may have more than one CRT, whether or not you are using different versions of Visual C++. For example, statically linking the CRT into multiple DLLs can present the same problem. Developers encountering this problem with static CRTs have been instructed to compile with /MD to use the CRT DLL. Now that the CRT DLL has been renamed to msvcr71.dll, applications may have some components linked to msvcrt.dll and others to msvcr71.dll. If your DLLs pass CRT resources across the msvcrt.dll and msvcr71.dll boundary, you will encounter issues with mismatched CRTs and need to recompile your project with Visual C++ .NET.

See Also

Run-Time Library Reference

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.