Differences between MD (d) and MT (d) compilation options

Source: Internet
Author: User

 

I. Differences between MD (d) and MT (d) compilation Options 1. Location of compilation options

Take VS2005 as an example:

1) Open the project's Property Pages dialog box

2) Click the C/C ++ section on the left.

3) Click the Code Generation section.

4) the sixth line of the Runtime Library Project on the right

2. Meaning of each setting Option

Compilation options

Include

Static link lib

Description

/MD

_ MT, _ DLL

MSVCRT. lib

Multi-thread, Release, DLL version Runtime Library

/MDd

_ DEBUG, _ MT, and _ DLL

MSVCRTD. lib

Multi-thread, Debug, DLL version Runtime Library

/MT

_ MT

LIBCMT. lib

Multi-thread, Release version Runtime Library

/MTd

_ DEBUG, _ MT

LIBCMTD. lib

Runtime Library of multi-thread and Debug Versions

 

To put it simply:

(1)/MD indicates that the Runtime Library provides a DLL by the operating system and is not integrated in the program.

(2)/MT, indicating that the Runtime Library is integrated by the program.

 

Ii./MD,/MT Selection 1. Why/MD? No/MT?

(1) The program does not need to statically link the Runtime Library, which can reduce the Software size;

(2) All modules adopt/MD and use the same heap. There is no issue of applying for A heap and releasing B heap.

2. Why do I select/MT instead of/MD?

(1) Some systems may not have the Runtime Library of the version required by the program. The program must link the Runtime Library to the static link.

3. You must select the same Runtime Library for multiple modules. 3. Select the heap space to be resolved by/MT

Different modules have their own C Runtime library code, or there is no C Runtime Library at all, resulting in each module having its own heap. If you apply for A space in heap A, releasing it in heap B will crash. The space applied for in module A must be released in module.

The DLL and DLLUser code of the attachment (: http://files.cnblogs.com/cswuyg/Test_MD_and_MT.rar), taking the string of STL as an example, verified this problem by modifying the compilation option. (When assigning values to strings, you need to release the original space and then apply for a new space to store new content .)

 

Iv. References

1. Microsoft's detailed introduction to MT and MD

Http://msdn.microsoft.com/en-us/library/2kzt1wy3 (v = VS.71). aspx

2. do not apply for module A or release Module B.

Http://www.cnblogs.com/minggoddess/archive/2010/12/15/1907179.html

3. Versions of the runtime Database

Http://www.cppblog.com/MichaelLiu/articles/10607.html

4. Discussion on heap space release on CSDN

Http://topic.csdn.net/t/20010112/09/57983.html

Http://topic.csdn.net/t/20031009/17/2338051.html

Http://topic.csdn.net/u/20090502/00/bf1602e3-ddf5-49b0-af81-8a23383f9ddc.html

Http://blog.csdn.net/blz_wowar/article/details/2176536

5. Different stacks of different modules

Http://www.cnblogs.com/WengYB/archive/2011/08/18/2144727.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.