首页 > 解决方案 > libcpmtd.lib 是做什么用的?

问题描述

突然之间,我的程序出现如下链接错误:

libcpmtd.lib(xlock.obj) : error LNK2038: 'RuntimeLibrary' unmatched. The value 'MTd_StaticDebug' 与 [project x] 不同,即:'MDd_DynamicDebug'

由于此错误突然出现在多台计算机上,我相信这不是由于意外修改任何文件造成的。

版本:Visual Studio 2013

问题一:

您能否提供有关此错误原因以及如何解决的任何提示?


我做了什么:我从项目设置的导入库列表中删除了 libcpmtd.lib,然后构建错误消失了,一切正常。

但是,我不确定 libcpmtd.lib 的用途是什么?谷歌告诉我里面有CRT,但是具体是什么内容呢?

也许这个库被添加了,然后从某个时间点不相关。

问题2:

libcpmtd.lib 中有什么?我想弄清楚删除 lib 后我可能丢失了什么。

标签: c++buildlib

解决方案


These are the C++ standard runtime libraries. With Visual C++, you have 2 options, which give you 4 permutations of the library it links to.

Debug v.s. Release

As it suggests, do you want the C++ runtime lib that has additional error checking?

Static v.s. Dynamic

If you happen to be compiling only a simple exe, then linking to the library statically should be fine. If however you have a large project consisting of multiple DLL's, then it makes sense to load the CRT dynamically (so it can be shared between the DLL's, rather than being duplicated into each one).

So what you have is a mis-configured build. You'll need to check the C/C++ Runtime Library settings for each library, DLL, and exe within your project (which you can find in your project settings, under C/C++ -> Code Generation).

You will need to make sure that each one links to the same runtime library (i.e. Debug DLL for all debug settings, Release DLL for all release settings).

If that doesn't fix it, then there are two other possible causes:

  1. You have started linking to a 3rd party library, and that's the cause of the CRT mis-match. Most libs ship debug and release builds for this reason, so hopefully you'll just need to update the libs you are linking to.
  2. You are inadvertently pulling in a Debug lib into a release build (or a release build lib, into a debug exe). For this you will need to check all of the additional library directories, and/or check to make sure all of the debug & release output directories are correct (i.e. you aren't accidentally compiling a debug lib into a release build folder).

推荐阅读