VC Runtime Library

Source: Internet
Author: User
Tags vc runtime

Compiling a program encountered several errors and found it to be a problem with the library settings during runtime. I found this was a good one on the Internet.

Original article:

VC project properties → configuration properties → C/C ++ → code generation → runtime libraries can adopt the following methods: multi-thread (/mt) and multi-thread debugging (/MTD) multi-thread DLL (/MD), multi-thread debugging DLL (/MDD ),Single-thread (/ml), single-thread debugging (/MLD).


Reusable library Switch Library Macro (s) Defined
Single threaded /Ml Libc (None)
Static multithread /Mt Libcmt _ Mt
Dynamic Link (DLL) /MD Msvcrt _ MT and _ DLL
Debug single threaded /MLD Libcd _ Debug
Debug static multithread /MTD Libcmtd _ Debug and _ Mt
Debug Dynamic Link (DLL) /MDD Msvcrtd _ Debug, _ Mt, and _ DLL



Among them, the option ending with lowercase "D" indicates the debug version, and the option not "D" indicates the release version. In large projects, the runtime libraries of all components and third-party libraries must be unified. Otherwise, lnk2005 blowout may occur.

The single-thread Runtime Library options/ml and/MLD were scrapped after vs2003.

/MT and/MTD indicate the static lib version of the multi-threaded CRT library. This option fully embeds the Runtime Library in the form of static lib during compilation. The executable file generated by this option does not need to participate in the Runtime Library DLL, and will have a slight performance improvement, however, the generated binary code is very bloated because it is chained into a large Runtime Library. When a project is embedded into multiple projects as a static Linked database, the memory management of the runtime database may exist in multiple copies, this will eventually cause a fatal "Invalid Address specified to rtlvalidateheap" problem. In addition, the/MT and/MTD options are no longer supported in C ++ and CLI hosting.

/MD and/MDD indicate the dynamic dll version of the multi-threaded CRT library, which will make the application use the multi-threaded DLL of a specific version of the Runtime Library. When linking, The Runtime Library msvcrxx will follow the traditional VC link DLL method. DLL import to msvcrt. the LIB link requires that the corresponding version of the VC Runtime Library be installed to reissue the component package (of course, it is also possible to put these Runtime Library DLL under the application directory ). Because the/MD and/MDD methods do not link the Runtime Library to the executable file, the size of the executable file can be effectively reduced. When multiple projects run in the MD mode, the same heap is used internally, and memory management is simplified, so that the problem of cross-module memory management can be mitigated.

Conclusion:/MD and/MDD will be the trend,/ml and/MLD methods should be abandoned in time,/MT and/MTD should not be used unless necessary.



How to link with the correct C run-time (CRT) Library

/MD,/mt,/LD (use the Runtime Library)



C ++/CLI if multiple projects "code generation/Runtime Library" are inconsistent, the lnk2022 error may be reported.

Reference: Getting error when compiling debug mode: C ++/cli-error lnk2022

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: 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.