[PE] Use and difference of VS compilation options MD, MDd, MT, MTd

tags: visual studio  Compilation options

###Date: 2017/10/23


1. Configuration of CRT compilation options

Location of compilation options:

Properties -> C/C++ -> Code Generation -> Runtime Library


2. Types of compilation options

(1)/MD 

Make applications use multithreaded and DLL-specific versions of the runtime library. Define _MT and _DLL and make the compiler put the library name MSVCRT.lib in the .obj file.Applications compiled with this option are statically linked to MSVCRT.lib. The library provides a code layer that allows the linker to resolve external references. The actual working code is contained in MSVCR90.DLL, and the library must be available to applications linked with MSVCRT.lib at runtime.When /MD is used with the _STATIC_CPPLIB preprocessor definition (/D_STATIC_CPPLIB), your application will link with the static multithreaded standard C++ (libcpmt.lib) instead of the dynamic version (msvcprt.lib), but still through msvcrt. lib is dynamically linked to the main CRT.
Please note that the combination of the _STATIC_CPPLIB preprocessor definition and the /clr or /clr:pure compiler options is not supported. For more information about the limitations of the /clr option, see /clr Restrictions.

(2)/MDd 
Define _DEBUG, _MT, and _DLL, and make the application use the debugging multithreading of the runtime library and specific to the DLL version. It also causes the compiler to put the library name MSVCRTD.lib in the .obj file.

(3)/MT 
Make the application use the multithreaded static version of the runtime library. Define _MT and have the compiler put the library name LIBCMT.lib in the .obj file so that the linker can use LIBCMT.lib to resolve external symbols.

(4)/MTd 
Define _DEBUG and _MT. This option also causes the compiler to put the library name LIBCMTD.lib in the .obj file so that the linker can use LIBCMTD.lib to resolve external symbols.

(5)/LD 
Create a DLL.
Pass the /DLL option to the linker. The linker looks for the DllMain function, but it is not required. If the DllMain function is not written, the linker will insert the DllMain function that returns TRUE.
Link the DLL startup code.
If no export (.exp) file is specified on the command line, an import library (.lib) is created; link the import library to the application that calls your DLL.
/Fe (named EXE file) is interpreted as a named DLL instead of an .exe file; the default program name becomes the base name .dll instead of the base name .exe.
Unless /MD is explicitly specified, /MT is implied.

(6)/LDd 

Create a debug DLL. Define _MT and _DEBUG.


Precautions:

/MD indicates that the runtime library is not integrated, the generated file is small, and the corresponding DLL is dynamically loaded when the program is run;

/MT means run-time library integration, and the generated file is large. When linking, the C/C++ run-time library is integrated into the program to become the code of the program.

The C runtime library is actually an implementation of standard C/C++ library functions. The compiler in VC++ provides dll to implement C/C++ library functions.


3. How to choose

The reason for choosing /MD: the file is small, the same heap is used, and there is no problem of A applying and B releasing;

The reason for choosing /MT: good portability and less dependence.

Reference: http://blog.csdn.net/whatday/article/details/7933133

http://blog.sina.com.cn/s/blog_6f7265cf0101nhs0.html

http://blog.csdn.net/u010059658/article/details/51026662

http://www.cnblogs.com/cuish/p/3146937.html

Intelligent Recommendation

Qt sets the runtime library MT, MTd, MD, MDd in pro, only suitable for the VS version of Qt

Transfer from: http://blog.csdn.net/caoshangpa/article/details/51416077 1. Set the runtime library in pro Recently, the following error occurred when using Qt5.6.0 (VS2013 version) to call a static li...

#visual studio# Runtime library MT, MTd, MD, MDd

In the development of the window program is often encountered when the compiled program is not able to run on another machine, which is generally caused by the installation of the corresponding runtim...

MT, MTd, MD, MDd explain MSVCRTD.LIB and LIBCMTD.LIB conflicts

Transfer from: The project development process encountered MSVCRTD.LIB and LIBCMTD.LIB conflicts, and later found the reason is that the code compiler compile c / c + + runtime version is not the same...

Openssl windows compile 64 bit mt mtd md mdd

reference: Openssl source download address:https://www.openssl.org/source/I used openssl-1.1.0i First install ActivePerl:https://www.activestate.com/activeperl/downloadsAfter loading it, if you start ...

Some links and problems between MTD/MT/MDD/MD and LIB/DLL

Where do you start talking about this topic? The blogger Xiaobai one, recently debugged the program (WIN-MSVC) and did not understand some basic problems, in line with the principle of meeting the pro...

More Recommendation

VC++ compile-time runtime library selection (/MT, /MTd, /MD, /MDd)

In VS, there are four options in project properties-"C/C++-"Code generation -" runtime library options: multi-threaded (/MT), multi-threaded debugging (/MTd) , Multi-threaded DLL (/MD),...

Qt sets the runtime library MT, MTd, MD, MDd in pro

Qt sets the runtime library MT, MTd, MD, MDd in pro, focusing onQMAKE_CFLAGS Multi-threaded debugging Dll (/MDd) corresponds to MD_DynamicDebug Multi-threaded Dll (/MD) corresponds to MD_DynamicReleas...

CMAKE Set MSVC Engineering MT/MTD/MD/MDD

Articles directory 0. Foreword 1. How to set up 1.1 Cmakelists code 1.2 Point 1: Policy 1.3 Key points 2: set_proprty 0. Foreword existMSVCEngineeringRight-click-> Properties,turn upConfiguration a...

libcef-compile operation mode-MTD/MT-MDD/MD

Article Directory 1. Open the project 2. Modify options 3. Verification test In an embedded running environment, most of the host software may use the MD mode to load and run the C++ runtime library. ...

VC runtime library /MD, /MDd and /MT, /MTd (to convert)

Let’s summarize their differences here. The 'd' behind represents the DEBUG version, and the RELEASE version without 'd' is the RELEASE version. First of all, /MT /MT is "multithread, stati...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top