Description of the default C and C++ libraries that a program will link with when built by using Visual C++


Summary


This article describes the default libraries LIBC[D].LIB, LIBCMT[D].LIB, LIBCI[D].LIB, LIBCIMT[D].LIB, LIBCP[D].LIB, LIBCPMT[D].LIB, MSVCRT[D].LIB, MSVCIRT[D].LIB, and MSVCPRT[D].LIB that a program will link with when built using Visual C++.

More Information


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 , multithreaded , or multithreaded DLL). 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:

vs2015部署—-下一代VC运行时库系统:the Universal CRT

image.png

CRT Library Features

C Run-Time Libraries (CRT)

  • Universal CRT (UCRT)
  • vcruntime library

VC6.使用的CRT库的DLL版本在MSVCRT.DLL中实现, 对应调试版本为MSVCRTD.LIB。
VC2005使用的CRT库的DLL版本在MSVCR80.DLL中实现,对应调试版本为MSVCR80.DLL。
VC2008使用的CRT库的DLL版本在MSVCR90.DLL中实现,对应调试版本为MSVCR90D.DLL。
VC2010使用的CRT库的DLL版本在MSVCR100.DLL中实现,对应调试版本为MSVCR100D.DLL。
VC2013使用的CRT库的DLL版本在MSVCR120.DLL中实现,对应调试版本为MSVCR120D.DLL。

C++ Standard Library

VC6.使用的C++类库的 DLL版本在MSVCP60.DLL中实现, 对应调试版本为MSVCP60D.LIB。
VC2005使用的C++类库的DLL版本在MSVCP80.DLL中实现,对应调试版本为MSVCP80.DLL。
VC2008使用的C++类库的 DLL版本在MSVCP90.DLL中实现,对应调试版本为MSVCP90D.DLL。
VC2010使用的C++类库的DLL版本在MSVCP100.DLL中实现,对应调试版本为MSVCP100D.DLL。

链接时都需要.lib文件,如果是导入库则运行期间还需要dll,如果是静态库测不需要dll

选择MT/MD等其实就是更改默认输入的.lib文件
可以在项目属性->链接器->输入 修改依赖项

WANNING: 尽量不要显示地添加运行时库进依赖项,即使你出现了“无法解析外部符号(看得出来是运行库函数 )”错误。The only possible way you have to do this explicitly is when you #include not a single standard C or C++ header. That’s quite hard to do. A wrong compile setting (C/C++, Code Generation, Runtime Library) is the more likely cause. Getting them mixed can cause very hard to diagnose runtime problems.

unresolved external symbol impwcsstr

有/MT,/MTd,/Md,/MDd四个选项,你必须让所有使用的库都使用相同的配置,否则就会有相应的提示,甚至可能会出现无法解析的函数。有时我们使用的库不是自己可以控制的,那么就只能把工程属性设置成河你使用的库相同的选项。 错误 1 error LNK2005: _free 已经在 libcmtd.lib(dbgheap.obj) 中定义 MSVCRT.lib

错误 2 error LNK2005: _malloc 已经在 libcmtd.lib(dbgheap.obj) 中定义 MSVCRT.lib

混合依赖运行时问题

整理:warning LNK4098: 默认库“LIBCMT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library

image.png
总之,你所依赖的库都要链接相同的运行时(相同MT/MD选项)