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 |
Runtime libraries of multithreading, release, and DLL versions-can only be used for Release versions |
/MDD |
_ Debug, _ Mt, and _ DLL |
Msvcrtd. Lib |
Multi-thread, debug, dll version Runtime Library-can only be used for debug version |
/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 indicates that the Runtime Library is integrated by the program, and the program no longer needs the operating system to provide the Runtime Library DLL.
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 type of Runtime Library for multiple modules.
3. Select the heap space to be resolved by/mt
Different modules have their own C Runtime library code, and each C Runtime Library has its own heap, 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.htm