---
title: "【error】LNK2005: already defined in LIBCMTD.lib(typinfo.obj)"
author: "SunRaIN_"
date: "2012-05-15T13:42:00Z"
tags: []
slug: "error-lnk2005-already-defined-in-libcmtd-lib-typinfo-obj"
draft: false
lastmod: "2012-12-21T15:50:02Z"
id: 1751833
url: "https://751401909.iteye.com/blog/1751833"
---

### 转载请注明出处：[http://blog.csdn.net/xiaowei\_cqu/article/details/7568333](http://blog.csdn.net/xiaowei_cqu/article/details/7568333)

这个问题的来源是这样的，我想要静态编译发布我程序，就是Runtime Library 设置为：Multi-threaded Debug (/MTd)

程序悲剧的报错了：

Error 2 error LNK2005: "private: \_\_thiscall type\_info::type\_info(class type\_info const &)" (??0type\_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)

Error 3 error LNK2005: "private: class type\_info & \_\_thiscall type\_info::operator=(class type\_info const &)" (??4type\_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)

一开始搜到这位可耐的网友：[http://sanqiaosiyou.blog.sohu.com/161348612.html](http://sanqiaosiyou.blog.sohu.com/161348612.html)

大致是两种库一起使用的问题，解决方案很粗暴，把libcmtd 直接Ignore 掉

Project Settings: -&gt; Configration Properties -&gt; Linker -&gt; Input -&gt; Ignore Specific Library: libcmtd

然后悲剧的通篇都是外部引用错误：

error LNK2019: unresolved external symbol \_ungetc referenced in function "bool \_\_cdecl std::\_Ungetc&lt;char&gt;(char const &,struct \_iobuf \*)" (??$\_Ungetc@D@std@@YA\_NABDPAU\_iobuf@@@Z)

很明显，我要用libcmtd！！！

网友说：libcmtd 这个库有时候不能忽略，忽略后会有不能解析的外部符号错误；其实有个方便的方法 链接时加入参数 /FORCE:MULTIPLE

然后我找了N长时间居然不知道怎么在vs2010里设置链接时的参数。。。。悲剧。。。。。

### 这中间还有个插曲

出现错误：Error 2 error LNK1181: cannot open input file 'kernel32.lib'

对于这个问题，这位辛勤的小网友带我饶了很多路：http://blogs.msdn.com/b/saurabh\_singh/archive/2009/01/30/getting-fatal-error-lnk1181-cannot-open-input-file-kernel32-lib.aspx

后来我在C盘找到这个 kernel32.lib 文件把地址添加到了Linker-&gt;Input里面，

又出现 Error 2 error LNK1181: cannot open input file '\*\*\*\*\*\*.lib'

貌似都是SDK里的lib，后来终于发现原来我不小心改掉了 Linker-&gt;Input-&gt;Additional Dependencies 里原本默认要加载的库：

![](http://my.csdn.net/uploads/201205/15/1337060778_6276.png)

要选上这个框！

### 再回到原来重复定义的问题

错误的大致意思是一个东西在 里重复定义了LIBCMTD.lib，报错的是msvcrtd.lib，所以改一下两个加载的顺序应该就可以。

然后发现VS2010默认加载的库配置是不能改的。。。。。

于是用了个很笨的方法：

先在Configuration Properties-&gt;Liner-&gt;Input-&gt;Ignore Specific Default Libraries中输入：LIBCMTD.lib;msvcrtd.lib

就是把这两个冲突库Ignore掉

再在Configuration Properties-&gt;Liner-&gt;Input-&gt;Additional Dependecies中添加：msvcrtd.lib;LIBCMTD.lib

把他们按不冲突的顺序再添加进来

这种无聊的方法还是有效的解决了问题

### ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

哈哈~