Select the correct c/C + + Runtime Library

Source: Internet
Author: User

This article is the translation of http://www.davidlenihan.com/2008/01/choosing_the_correct_cc_runtim.html, if there are errors, please correct me

The runtime library includes a number of basic functions like memory allocation, output and string manipulation (copy, compute length), etc.

When you set up an application or library for C/C + +, you must select the C + + runtime, in vs2005, you can select this button: Project->properties...->configuration properties- >c/c++->code generation->runtime Library:

Here are 4 options:

1 Multi-Threading (/MT)

2 Multi-threaded debugging (/MTD)

3 multi-threaded dynamic link library DLL (/MD)

4 Multi-threaded dynamic link library debugging (/MDD)

The runtime of C + + relies on the run-Library of C.. The runtime version of C must match the runtime version of C + +. Therefore, these options are applied to the runtime of C and C + +.

In previous VS versions, these were single-threaded. Those versions are faster than multithreaded execution. However, in multithreaded applications, it is not safe to use them. I think the single-line libraries is decreasing because multicore is now a universal presence. and multithreaded applications need to take advantage of multicore.

(In previous versions of Visual Studio, you had additional options that were single-threaded. These versions would execute faster on a single core than the multi-threaded versions. However, they were not safe to use in a multi-threaded application. I ' m guessing these libraries were dropped since multiple cores are quickly becoming ubiquitous and multi-threaded applicat Ions is needed to take advantage of these extra cores.)

There are four choices for these two variables

    • Debug version (Debug) vs Release version (release)
    • Dynamic link library (DLL) vs Static Library

The first variable is simple, and the debug version is applied in the internal software that is not given to the customer. The debug runtime cannot legally contain your application. Let's just say that you can't give the customer the debug version of the software. It should be the release version of the runtime

Debug runtime allows you to have some useful debugging help, such as error reporting and tracking memory leaks, to learn more about the debug function, see http://msdn.microsoft.com/en-us/library/zh712wwf%28VS.80%29.aspx

The next variable is a dynamic-link library (DLL) or a static library. In general, we should use DLLs, and when you see the following, you can consider the static library version:

    • You have a small app that you don't want to waste memory letting the runtime call something you don't want above
    • You want a simple application that does not depend on the extra runtime DLL

These instructions run very well when your application does not need other libraries. But this rarely happens. Using an extra version of the runtime in your application Microsoft lists a few vague warnings in their documentation.

The goal is to use only one runtime library in your entire application.

But it's almost impossible because you don't have permissions when you use libraries for other class libraries. For example, OpenGL (Open graphic Library) needs to use the class library. If your application or other class library is not using the same class library as OpenGL, then you are using several class libraries at the same time.

How do we know which class library a exe,dll,lib,obj uses, using this command:,

dumpbin /all XXXX | find /i "msvcr"

XXX means you want to know the Exe/dll/lib/obj

To know what the results of the operation represent, refer to: http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx

If you don't get anything, chances are you're using a static library.

Even if you know which runtime to use, you will find it impossible to make the application use only a single runtime library. If you match the runtime, it is possible that a class library is using the vs7.0 version (Msvct.dll) but you can only access the vs8.0 class library.

Therefore, in addition to certain circumstances, the class library mixed with a small relationship. A good class library should avoid these situations, and then the class library does not have much to do with when it matches.

Select the correct c/C + + Runtime Library

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.