C Run-Time Libraries (CRT) from msdn

This topic discusses the various .lib files that comprise the C run-time libraries as well as their associated compiler options and preprocessor directives.

本主题讨论了组成C运行时库的各种.lib文件,以及和它们相关的编译器选项和预处理器指示符。

 

C Run-Time Libraries (CRT)

The following libraries contain the C run-time library functions.

下面的库包含了C运行时库函数。

 

C运行时库
(无iostream和C++标准库)
相关的DLL 特征 选项 预处理器指示符
libcmt.lib 无,静态链接。 多线程,静态链接 /MT _MT
msvcrt.lib msvcr90.dll 多线程,动态链接(MSVCR90.DLL的导入库)。注意,如果使用C++标准库,则程序的运行需要MSVCP90.DLL。 /MD _MT, _DLL
libcmtd.dll 无,静态链接。 多线程,静态链接(调试) /MTd _DEBUG, _MT
msvcrtd.lib msvcr90d.dll 多线程,动态链接(MSVCR90D.DLL)(调试) /MDd _DEBUG, _MT, _DLL
msvcmrt.lib msvcm90.dll C运行时导入库。用于托管/原生混合代码。 /clr  
msvcurt.lib msvcm90.dll 编译为100%纯MSIL码的C运行时导入库。所有代码使用MSIL的ECMA URT标准编译。 /clr:pure  

 

The single-threaded CRT (libc.lib, libcd.lib) (formerly the /ML or /MLd options) is no longer available. Instead, use the multithreaded CRT. See Multithreaded Libraries Performance.

单线程CRT(libc.lib,libcd.lib)(以前的/ML或/MLd选项)不再可用。取而代之的是使用多线程CRT。

 

If you link your program from the command line without a compiler option that specifies a C run-time library, the linker will use LIBCMT.LIB. This is different from previous versions of Visual C++ which used LIBC.LIB, the single-threaded library, instead.

如果从命令行链接程序,而没有使用指定C运行时库的编译器选项时,链接器将使用LIBCMT.LIB。这不同于之前版本的Visual Studio,它使用LIBC.LIB,单线程库。

 

Using the statically linked CRT implies that any state information saved by the C runtime library will be local to that instance of the CRT. For example, if you use strtok, _strtok_l, wcstok, _wcstok_l, _mbstok, _mbstok_l when using a statically linked CRT, the position of the strtok parser is unrelated to the strtok state used in code in the same process (but in a different DLL or EXE) that is linked to another instance of the static CRT. In contrast, the dynamically linked CRT shares state for all code within a process that is dynamically linked to the CRT. This concern does not apply if you use the new more secure versions of these functions; for example, strtok_s does not have this problem.

 

Because a DLL built by linking to a static CRT will have its own CRT state, it is not recommended to link statically to the CRT in a DLL unless the consequences of this are specifically desired and understood. For example, if you call _set_se_translator in an executable that loads the DLL linked to its own static CRT, any hardware exceptions generated by the code in the DLL will not be caught by the translator, but hardware exceptions generated by code in the main executable will be caught.

因为链接到静态CRT的DLL将拥有它自己的CRT状态,所以不推荐在DLL中静态链接到CRT,除非确实需要和理解这样做的后果。例如,在一个加载了链接到它自己静态CRT的DLL的程序中调用_set_se_translator,DLL中代码所产生的任何硬件异常将不会被这个translator捕捉到,但主可执行程序代码所产生的硬件异常将被捕捉到。

 

Standard C++ Library

C++标准库 特征 选项 预处理器指示符
libcpmt.lib 多线程,静态链接 /MT _MT
msvcprt.lib 多线程,动态链接(MSVCP90.DLL的导入库 /MD _MT, _DLL
libcpmtd.lib 多线程,静态链接(调试) /MTd _DEBUG, _MT
msvcprtd.lib 多线程,动态链接(MSVCR90D.DLL)(调试) /MDd _DEBUG, _MT, _DLL

 

Note   Starting in Visual C++ 2005, LIBCP.LIB and LIBCPD.LIB (via the old /ML and /MLd options) have been removed. Use LIBCPMT.LIB and LIBCPMTD.LIB instead via the /MT and /MTd options.

注意   从Visual C++ 2005开始,libcp.lib和libcpd.lib(老的/ML和/MLd选项)已经被移除。通过/MT和/MTd使用libcpmt.lib和libcpmtd.lib取代。

 

When you build a release version of your project, one of the basic C run-time libraries (LIBCMT.LIB, MSVCMRT.LIB, MSVCRT.LIB) is linked by default, depending on the compiler option you choose (multithreaded, DLL, /clr). If you include one of the Header Files in your code, a Standard C++ Library will be linked in automatically by Visual C++ at compile time. For example:

当构建工程的release版本时,其中之一基本C运行时库(libcmt.lib、msvcmrt.lib、msvcrt.lib)默认被链接,具体是哪一个取决于你选择的编译器选项(多线程、DLL、/clr)。如果代码中包含其中一个C++标准库头文件(http://msdn.microsoft.com/en-us/library/a7tkse1h(VS.80).aspx)时,Visual C++将在编译期自动链接C++标准库。例如:

#include <ios>

 

What is the difference between msvcrt.dll and msvcr90.dll?

The msvcrt.dll is now a "known DLL," meaning that it is a system component owned and built by Windows. It is intended for future use only by system-level components.

 

What problems exist if an application uses both msvcrt.dll and msvcr90.dll?

If you have a .lib or .obj file that needs to link to msvcrt.lib, then you should not have to recompile it to work with the new msvcrt.lib in Visual C++ 2008. The .lib or .obj file may rely on the sizes, field offsets, or member function names of various CRT classes or variables, and those should all still exist in a compatible way. When you relink against msvcrt.lib, your final EXE and DLL image will now have a dependency on msvcr90.dll instead of msvcrt.dll.

If you have more than one DLL or EXE, then you may have more than one CRT, whether or not you are using different versions of Visual C++. For example, statically linking the CRT into multiple DLLs can present the same problem. Developers encountering this problem with static CRTs have been instructed to compile with /MD to use the CRT DLL. Now that the CRT DLL has been renamed to msvcr90.dll, applications may have some components linked to msvcrt.dll and others to msvcr90.dll. If your DLLs pass CRT resources across the msvcrt.dll and msvcr90.dll boundary, you will encounter issues with mismatched CRTs and need to recompile your project with Visual C++ 2008.

If your program is using more than one version of the CRT, some care is needed when passing certain CRT objects (such as file handles, locales and environment variables) across DLL boundaries. For more information on the issues involved and how to resolve them, see Potential Errors Passing CRT Objects Across DLL Boundaries.

posted @ 2009-04-10 15:38  DEMENTiA  阅读(1565)  评论(0编辑  收藏  举报