[vs][v.2008]ERROR:1169 2005 解决
1 错误 20 error LNK2005: "bool __cdecl std::operator==<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$?8DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 2 错误 18 error LNK2005: "public: __thiscall std::_Container_base_secure::_Container_base_secure(void)" (??0_Container_base_secure@std@@QAE@XZ) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 3 错误 13 error LNK2005: "public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (??1_Container_base_secure@std@@QAE@XZ) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 4 错误 12 error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) 已经在 libcpmtd.lib(xlock.obj) 中定义 msvcprtd.lib 5 错误 11 error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) 已经在 libcpmtd.lib(xlock.obj) 中定义 msvcprtd.lib 6 错误 14 error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 7 错误 15 error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 8 错误 16 error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 9 错误 23 error LNK2005: "public: char & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator[](unsigned int)" (??A?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAADI@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 10 错误 17 error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 11 错误 21 error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::append(char const *,unsigned int)" (?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 12 错误 19 error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator=(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 13 错误 10 error LNK2005: "public: void __thiscall std::_Container_base_secure::_Orphan_all(void)const " (?_Orphan_all@_Container_base_secure@std@@QBEXXZ) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 14 错误 22 error LNK2005: "public: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::swap(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z) 已经在 gtestd.lib(gtest-all.obj) 中定义 msvcprtd.lib 15 错误 9 error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) 已经在 libcpmtd.lib(stdthrow.obj) 中定义 msvcprtd.lib 16 错误 24 fatal error LNK1169: 找到一个或多个多重定义的符号 d:\workspace\unittest\dist\Debug\dti_gtest.exe 1
场景:在使用gtest框架做单元测试时,因测试库的运行库为(多线程调试 DLL (/MDd)) ,导致与gtest的运行库(多线程调试(/MTd)) 不同而报上述错误.
解决办法:把相对应的库 属性->c++->代码生成->运行库设置为 多线程调试(/MTd)