When you build a release (or debug) version of your project in Visual C++, one of the basic C Runtime libraries (LIBC[D].LIB, LIBCMT[D].LIB, and MSVCRT[D].LIB) is linked by default, depending on the compiler option you choose (single-threaded <ML[d]>, multithreaded <MT[d]>, or multithreaded DLL<MD[d]>). A library from the Standard C++ Library or one from the old iostream library may also be linked depending on the headers you use in your code. For example, consider the following cases:
Note It may seem that headers without the .h extension are Standard C++ headers and that headers with the .h extension are C Runtime headers or old iostream headers. This is not true. As explained below, the files <useoldio.h> and <use_ansi.h> determine the libraries your application will link with.
Actually, there are two header files, <useoldio.h> and <use_ansi.h>, that contain #pragmas. The #pragmas force either the old iostream library or the Standard C++ library to be linked in by default.
The header file <useoldio.h> contains #pragma statements, which force the old iostream library to be linked in. All old iostream headers include <useoldio.h>. So, if you include any old iostream header in your application, the old iostream library will be linked by default. The following table lists all the header files that include <useoldio.h>.
You cannot mix calls to the old iostream library and the new Standard C++ Library in Visual C++ 4.2.
Case 1: Sample program test1.cpp
// test1.cpp
void main()
{
}
- If you build test1.cpp using the /ML (or /MLd, for a debug build) compiler option, your program will link with LIBC.LIB (or LIBCD.LIB, for debug build), in addition to other libraries.
Note The /ML and /MLd library compiler options for static single-threaded libraries were removed in Visual C++ 2005 and in later versions of Visual C++.
- If you build test1.cpp using the /MT (or /MTd, for a debug build) compiler option, your program will link with LIBCMT.LIB (or LIBCMTD.LIB, for debug build), in addition to other libraries.
- If you build test1.cpp using the /MD (or /MDd, for a debug build)compiler option, your program will link with MSVCRT.LIB (or MSVCRTD.LIB, for debug build), in addition to other libraries. In this case, your program will be dependent on MSVCRT.DLL (or MSVCRTD.DLL for debug build).
Case 2: Sample program test2.cpp
// test2.cpp
#include <iostream>
void main()
{
}
- If you build test2.cpp using the /ML (or /MLd, for a debug build) compiler option, your program will link with LIBC.LIB (or LIBCD.LIB, for debug build) and LIBCP.LIB (or LIBCPD.LIB, for debug build), in addition to other libraries.
Note The /ML and /MLd library compiler options for static single-threaded libraries were removed in Visual C++ 2005 and in later versions of Visual C++.
- If you build test2.cpp using the /MT (or /MTd, for a debug build) compiler option, your program will link with LIBCMT.LIB (or LIBCMTD.LIB, for debug build) and LIBCPMT.LIB (or LIBCPMTD.LIB, for debug build), in addition to other libraries.
- If you build test2.cpp using the /MD (or /MDd, for a debug build) compiler option, your program will link with MSVCRT.LIB (or MSVCRTD.LIB, for debug build) and MSVCPRT.LIB (or MSVCPRTD.LIB, for debug build), in addition to other libraries.
For Microsoft Visual C++ 2008, your program will be dependent on MSVCR90.DLL and MSVCP90.DLL (or MSVCR90D.DLL and MSVCP90D.DLL for debug build).
For Microsoft Visual C++ 2005, your program will be dependent on MSVCR80.DLL and MSVCP80.DLL (or MSVCR80D.DLL and MSVCP80D.DLL for debug build).
For Microsoft Visual C++ 2003, your program will be dependent on MSVCR71.DLL and MSVCP71.DLL (or MSVCR71D.DLL and MSVCP71D.DLL for debug build).
For Microsoft Visual C++ 2002, your program will be dependent on MSVCR70.DLL and MSVCP70.DLL (or MSVCR70D.DLL and MSVCP70D.DLL for debug build).
For Microsoft Visual C++ 6.0, your program will be dependent on MSVCRT.DLL and MSVCP60.DLL (or MSVCRTD.DLL and MSVCP60D.DLL for debug build).
For Microsoft Visual C++ 5.0, your program will be dependent on MSVCRT.DLL and MSVCP50.DLL (or MSVCRTD.DLL and MSVCP50D.DLL for debug build).
For Microsoft Visual C++ 4.2, your program will be dependent on MSVCRT.DLL (or MSVCRTD.DLL for debug build) and MSVCPRT.LIB (or MSVCPRTD.LIB, for debug build).
Case 3: Sample program test3.cpp
Note The stream header files that have the .h extension (include <useoldio.h>) have been deprecated in Visual C++ 2002 and have been removed in Visual C++ 2005 and in Visual C++ 2003. Therefore, the following sample will not work in a version of Visual C++ later than Visual C++ 2002.
// test3.cpp
#include <iostream.h>
void main()
{
}
- If you build test3.cpp using the /ML (or /MLd, for a debug build) compiler option, your program will link with LIBC.LIB (or LIBCD.LIB, for debug build) and LIBCI.LIB (or LIBCID.LIB, for debug build), in addition to other libraries.
Note The /ML and /MLd library compiler options for static single-threaded libraries were removed in Visual C++ 2005 and in later versions of Visual C++.
- If you build test3.cpp using the /MT (or /MTd, for a debug build) compiler option, your program will link with LIBCMT.LIB (or LIBCMTD.LIB, for debug build) and LIBCIMT.LIB (or LIBCIMTD.LIB, for debug build), in addition to other libraries.
- If you build test3.cpp using the /MD (or /MDd, for a debug build) compiler option, your program will link with MSVCRT.LIB (or MSVCRTD.LIB, for debug build) and MSVCIRT.LIB (or MSVCIRTD.LIB, for debug build) in addition to other libraries. In this case, your program will be dependent on MSVCRT.DLL (or MSVCRTD.DLL for debug build) and MSVCIRT.DLL (or MSVCIRTD.DLL for debug build).
Note It may seem that headers without the .h extension are Standard C++ headers and that headers with the .h extension are C Runtime headers or old iostream headers. This is not true. As explained below, the files <useoldio.h> and <use_ansi.h> determine the libraries your application will link with.
Actually, there are two header files, <useoldio.h> and <use_ansi.h>, that contain #pragmas. The #pragmas force either the old iostream library or the Standard C++ library to be linked in by default.
The header file <useoldio.h> contains #pragma statements, which force the old iostream library to be linked in. All old iostream headers include <useoldio.h>. So, if you include any old iostream header in your application, the old iostream library will be linked by default. The following table lists all the header files that include <useoldio.h>.
Old iostream headers
| FSTREAM.H | IOMANIP.H |
| IOS.H | IOSTREAM.H |
| ISTREAM.H | OSTREAM.H |
| STDIOSTR.H | STREAMB.H |
| STRSTREA.H |
Note <useoldio.h> applies only to Visual C++ .NET 2003 and earlier versions. Because the old iostream library was removed from Visual C++ 2003 and later versions, the <useoldio.h> header was also removed.
The header file <use_ansi.h> contains #pragma statements that force the Standard C++ Library to be linked in. All Standard C++ Headers include <use_ansi.h>. So if you include any Standard C++ header in your application, the Standard C++ library will be linked by default. The following table lists all the header files that include <use_ansi.h>.
Standard C++ Headers
| ALGORITHM | BITSET | COMPLEX | DEQUE |
| FSTREAM | FUNCTIONAL | IOMANIP | IOS |
| IOSFWD | IOSTREAM | ISTREAM | ITERATOR |
| LIMITS | LIST | LOCALE | MAP |
| MEMORY | NUMERIC | OSTREAM | QUEUE |
| SET | SSTREAM | STACK | STDEXCEPT |
| STREAMBUF | STRING | STRSTREAM | TYPEINFO |
| UTILITY | VALARRAY | VECTOR | XIOSBASE |
| XLOCALE | XLOCINFO | XLOCMON | XLOCNUM |
| XLOCTIME | XMEMORY | XSTRING | XTREE |
| XUTILITY | YMATH.H |
| Compile option | Libraries linked with |
| /ML (VC++ .NET 2003 and earlier) | LIBC.LIB, LIBCP.LIB |
| /MLd (VC++ .NET 2003 and earlier) | LIBCD.LIB, LIBCPD.LIB |
| /MT | LIBCMT.LIB, LIBCPMT.LIB |
| /MTd | LIBCMTD.LIB, LIBCPMTD.LIB |
| /MD | MSVCRT.LIB, MSVCPRT.LIB |
| /MDd | MSVCRTD.LIB, MSVCPRTD.LIB |
Summary Table for CRT DLLs Used
| Import library linked with | DLLs used (Visual C++ 5.0|6.0) | DLLs used (Visual C++ .NET 2002|Visual C++ .NET 2003) | DLLs used (Visual C++ 2005|Visual C++ 2008 |
| MSVCRT.LIB | MSVCRT.DLL | MSVCR7(0|1).DLL | MSVCR(80|90).DLL |
| MSVCRTD.LIB | MSVCRTD.DLL | MSVCR7(0|1)D.DLL | MSVCR(80|90)D.DLL |
| MSVCPRT.LIB | MSVCP(5|6)0.DLL | MSVCP7(0|1).DLL | MSVCP(80|90).DLL |
| MSVCPRTD.LIB | MSVCP(5|6)0D.DLL | MSVCP7(0|1)D.DLL | MSVCP(80|90)D.DLL |
| MSVCIRT.LIB | MSVCIRT.DLL | ||
| MSVCIRTD.LIB | MSVCIRTD.DLL |
本文详细介绍了在使用Visual C++构建项目时,如何根据不同的编译器选项选择链接到相应的C运行库(CRT)。包括单线程、多线程和多线程DLL等不同配置下,标准C++库与旧版iostream库的使用区别。
Back to the top
8857

被折叠的 条评论
为什么被折叠?



