Export (0) Print
Expand All
Expand Minimize
5 out of 12 rated this helpful - Rate this topic

/MD, /ML, /MT, /LD (Use Run-Time Library)

/MD[d]
/ML[d]
/MT[d]
/LD[d]

These options select either single-threaded or multithreaded run-time routines, indicate if a multithreaded module is a DLL, and select retail or debug versions of the run-time library.

Option Description
/MD Defines _MT and _DLL so that both multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. This option also causes the compiler to place the library name MSVCRT.lib into the .obj file.

Applications compiled with this option are statically linked to MSVCRT.lib. This library provides a layer of code that allows the linker to resolve external references. The actual working code is contained in MSVCR71.DLL, which must be available at run time to applications linked with MSVCRT.lib.

When /MD is used with _STATIC_CPPLIB defined (/D_STATIC_CPPLIB) it will cause the application to link with the static multithread Standard C++ Library (libcpmt.lib) instead of the dynamic version (msvcprt.lib) while still dynamically linking to the main CRT via msvcrt.lib.

/MDd Defines _DEBUG, _MT, and _DLL so that debug multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. It also causes the compiler to place the library name MSVCRTD.lib into the .obj file.
/ML Causes the compiler to place the library name LIBC.lib into the .obj file so that the linker will use LIBC.lib to resolve external symbols. This is the compiler's default action. LIBC.lib does not provide multithread support.
/MLd Defines _DEBUG and causes the compiler to place the library name LIBCD.lib into the .obj file so that the linker will use LIBCD.lib to resolve external symbols. LIBCD.lib does not provide multithread support.
/MT Defines _MT so that multithread-specific versions of the run-time routines are selected from the standard header (.h) files. This option also causes the compiler to place the library name LIBCMT.lib into the .obj file so that the linker will use LIBCMT.lib to resolve external symbols. Either /MT or /MD (or their debug equivalents /MTd or /MDd) is required to create multithreaded programs.
/MTd Defines _DEBUG and _MT. Defining _MT causes multithread-specific versions of the run-time routines to be selected from the standard .h files. This option also causes the compiler to place the library name LIBCMTD.lib into the .obj file so that the linker will use LIBCMTD.lib to resolve external symbols. Either /MTd or /MDd (or their non-debug equivalents /MT or MD) is required to create multithreaded programs.
/LD Creates a DLL.

Passes the /DLL option to the linker. The linker looks for, but does not require, a DllMain function. If you do not write a DllMain function, the linker inserts a DllMain function that returns TRUE.

Links the DLL startup code.

Creates an import library (.lib), if an export (.exp) file is not specified on the command line; you link the import library to applications that call your DLL.

Interprets /Fe as naming a DLL rather than an .exe file; the default program name becomes basename.dll instead of basename.exe.

Changes the default run-time library support to /MT if you have not explicitly specified one of the /M options.

/LDd Creates a debug DLL. Defines _DEBUG.
Caution   Do not mix static and dynamic versions of the run-time libraries. Having more than one copy of the run-time libraries in a process can cause problems, because static data in one copy is not shared with the other copy. The linker prevents you from linking with both static and dynamic versions within one .exe file, but you can still end up with two (or more) copies of the run-time libraries. For example, a dynamic-link library linked with the static (non-DLL) versions of the run-time libraries can cause problems when used with an .exe file that was linked with the dynamic (DLL) version of the run-time libraries. (You should also avoid mixing the debug and non-debug versions of the libraries in one process.)

For more information on using the debug versions of the run-time libraries, see Run-Time Library Reference.

Knowledge Base article Q140584 also discusses how to choose the appropriate C run-time library.

For further discussion of DLLs, see DLLs.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
  2. Click the C/C++ folder.
  3. Click the Code Generation property page.
  4. Modify the Runtime Library property.

To set this compiler option programmatically

See RuntimeLibrary Property.

See Also

Compiler Options | Setting Compiler Options

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