C Runtime Library and a deep understanding of the meaning of compilation options-02

Source: Internet
Author: User
Tags vc runtime
The following content is from the network and the author is not clear. Transferred from:Http://advancedcj.wordpress.com/2010/06/18/c-runtime-library-2/

(Link)

IV differences between various C Runtime Libraries

Compiler link options:

Which C Runtime Library is merged during visual c ++ compilation? Program Depending on the Compilation option, the option tells the compiler application the version of the C standard library to be used. Options related to the standard library:/ml,/MLD,/mt,/MTD,/MD,/MDD/ml corresponding to the single-thread static version of the standard library (libc. lib);/MT corresponds to the standard library (libcmt. lib). At this time, the compiler will automatically define the _ Mt macro;/MD corresponding to the multi-threaded dll version (imported into msvcrt. lib, DLL is msvcrt. the compiler automatically defines two macros: _ MT and _ DLL. The option D will allow the compiler to automatically define one more _ debug macro, indicating that the debugging version of the corresponding standard library will be used. Therefore: /MLD corresponds to the single-thread static standard library (libcd. lib);/MTD corresponds to the multi-threaded static standard library (libcmtd. lib);/MDD corresponds to the multi-threaded DLL standard library for debugging (imported to msvcrtd. lib, DLL is msvcrtd. DLL ). In vc2005/vc6.0, use the following method to set the C run-time library to be connected to your program: vc2005: to find these options in the development environment, click Project on the project menu, choose properties... Item. then click the C/C ++ tab, and click code generation in the category box. see the Runtime library drop-down box. vc6.0: to find these options in the development environment, click Settings on the project menu. then click the C/C ++ tab, and click code generation in the category box. see the use run-time library drop-down box. differences between various C Runtime libraries: (1) Single-threaded libraries with static links can only be used for single-threaded applications, and the objective of the C Runtime Library Code It is finally compiled in the binary file of the application. You can use the/ml compilation option to set a single-threaded library that uses static links for Visual C ++. (2) The target code of the static multi-threaded library with static links is finally compiled in the binary file of the application, but it can be used in the multi-threaded program. You can use the/MT compilation option to set a single-threaded library that uses static links for Visual C ++. (3) dynamically linked runtime libraries save all C library functions in a separate Dynamic Linked Library msvcrtxx. dll. msvcrtxx. dll handles multithreading issues. You can use the/MD compilation option to set the Runtime Library that uses dynamic links in Visual C ++. The/MLD,/MTD, or/MDD options use the debug Runtime Library (the runtime function library of the debug version), which corresponds to/ml,/mt, or/MD respectively. The Runtime Library of the debug version contains debugging information and uses some protection mechanisms to help identify errors and enhance the detection of errors. Therefore, it cannot match the release version in terms of running performance. Most of the time a program is running in these runtime libraries. When a program (release version) is compiled, VC Automatically releases the corresponding Runtime Library file (libc) based on the Compilation options (single thread, multi-thread, or DLL. lib, libcmt. lib or import library msvcrt. lib. Note: Modify the compilation option and change/MD or/MDD to/Mt or/MTD to implement static links to the VC Runtime Library, the vc dll is no longer needed at runtime. (Static links directly compile the target code in the binary file of the application, so that no DLL is required during running) start to try the Google test unit testing tool (it's also a ghost of MTD/MDD !) With VC Runtime Library details today tried Google test, the environment is vs2008. download gtest 1.30, respectively in debug and release mode to compile the project files under the gtest-1.3.0msvc. The gtest static library (gtestd. lib) and release version gtest static library (gtest. lib ). create a test Demo project. Create a Win32 console project, set the additional include directory as the gtest-1.3.0include in the project properties, and add the corresponding additional dependency gtestd. lib or gtest. Lib according to the compiling environment. Set the path of the additional library to the corresponding lib path. Compile the project after writing the test program, and there are many "external symbols that cannot be parsed" errors. But has lib been added ?! Cause of error: the Runtime Library settings of C ++ in project properties/C ++/code generation/options are different from those of gtest compiling. When compiling the gtest library, the Runtime Library in the project settings is set to "multi-thread debugging (/MTD)", while the default project in vs2008 is "multi-thread debugging DLL (/MDD )", as a result, many function symbols cannot be parsed. Solution: Modify the Runtime Library settings. The Runtime Library must be the same as the Runtime Library settings that generate gtest. Lib. The use of third-party libraries may cause lnk2005 errors-repeated definition errors, which are generally caused by inconsistent links between third-party libraries and existing projects. For example, third-party libraries use static links, the current project uses dynamic links or a third-party library uses a single thread. This error is caused when the current project uses multiple threads.
Related Article

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.