http://msdn.microsoft.com/en-us/library/Aa984820
The following table lists the release versions of the C run-time library files, along with their associated compiler options and environment variables. Prior to Visual C++ 4.2, the C run-time libraries contained the iostream library functions. In Visual
C++ 4.2 and later, the old iostream library functions have been removed from LIBC.LIB, LIBCMT.LIB, and MSVCRT.LIB. (This change was made because the Standard C++ library has been added to Visual C++, and it contains a new set of iostream libraries. Thus, two
sets of iostream functions are now included in Visual C++.) The old iostream functions now exist in their own libraries: LIBCI.LIB, LIBCIMT.LIB, and MSVCIRT.LIB. The new iostream functions, as well as many other new functions, exist in the Standard C++ libraries:
LIBCP.LIB, LIBCPMT.LIB, and MSVCPRT.LIB.
When you build a release version of your project, one of the basic C run-time libraries (LIBC.LIB, LIBCMT.LIB, and MSVCRT.LIB) is linked by default, depending on the compiler option you choose (single-threaded, multithreaded, or DLL). Depending on the headers you use in your code, a library from the Standard C++ libraries or one from the old iostream libraries may also be linked:
- If you include aStandard C++ library header in your code, a Standard C++ library will be linked in automatically by Visual C++ at compile time. For example:
#include <ios>
- If you include an old iostream library header, an old iostream library will be linked in automatically by Visual C++ at compile time. For example:
#include <ios.h>
Headers determine whether a Standard C++ library, an old iostream library, or neither will be linked. Compiler options determine which of the libraries to be linked is the default (single-threaded, multithreaded, or DLL). When a specific library compiler option is defined, that library is considered to be the default and its environment variables are automatically defined.
在vc++4.1版本(包括4.1版)之前,运行库是Libc.lib, Libcmt.lib, Msvcrt.lib ,这些库包含了旧的iostream库,而这些旧的iostream库现在已经从libc.lib, libcmtlib, msvcrt.lib 中独立出来,如果链接时没有 /NODEFAULTLIB,默认链接时用 libci.lib , libcimt.lib , msvcirt.lib ,而如果指定 /NODEFAULTLIB ,则需要手动添加库。
如:
main.cpp:
#include <iostream.h> int main() { cout<<"hello"<<endl; return 0; }
编译而不链接:
cl main.cpp /c
这里等同于 cl main.cpp /c /ML
/ML 为缺省状态下的运行库
其中,/c 是编译而不链接,/ML为缺省选项,对应于单线程静态版标准程序库 libc.lib
取得main.obj ,用文本打开看,里面有一行
-defaultlib:libci -defaultlib:LIBC -defaultlib:OLDNAMES
然后链接:
link main.obj /nodefaultlib libc.lib libci.lib kernel32.lib
如果调整main.cpp:
#include <iostream> using namespace std; int main() { cout<<"hello"<<endl; return 0; }编译后再查看main.obj ,发现变成
-defaultlib:libcp -defaultlib:LIBC -defaultlib:OLDNAMES
则相应的调整链接命令行:
link main.obj /nodefaultlib libc.lib libcp.lib kernel32.lib
参考:http://blog.csdn.net/yang3yang/article/details/4360669
C Run-Time Library (without iostream) | Characteristics | Option | Defined |
LIBC.LIB | Single threaded, static link | /ML | |
LIBCMT.LIB | Multithreaded, static link | /MT | _MT |
MSVCRT.LIB | Multithreaded, dynamic link (import library for MSVCRT.DLL) | /MD | _MT, _DLL |
Standard C++ Library | Characteristics | Option | Defined |
LIBCP.LIB | Single threaded, static link | /ML | |
LIBCPMT.LIB | Multithreaded, static link | /MT | _MT |
MSVCPRT.LIB | Multithreaded, dynamic link (import library for MSVCRT.DLL) | /MD | _MT, _DLL |
Old Iostream Library | Characteristics | Option | Defined |
LIBCI.LIB | Single threaded, static link | /ML | |
LIBCIMT.LIB | Multithreaded, static link | /MT | _MT |
MSVCIRT.LIB | Multithreaded, dynamic link (import library for MSVCIRT.DLL) | /MD | _MT, _DLL |