如何修复静态库?

3
我正在尝试学习如何调试静态库,并尤其是尝试修复JsonCpp。 我可以使用哪些项目设置来在Visual Studio的输出窗口中查看确切的链接内容?
以下是我得到的错误:
Error   1   error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj)    msvcprtd.lib

Error   2   error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj) msvcprtd.lib

Error   3   error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj)    msvcprtd.lib

Error   4   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) already defined in Core.obj msvcprtd.lib

Error   5   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) already defined in Core.obj   msvcprtd.lib

Error   6   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) already defined in Core.obj msvcprtd.lib

Error   7   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) already defined in Core.obj    msvcprtd.lib

Error   8   error LNK2005: "public: void __thiscall std::_Container_base_secure::_Orphan_all(void)const " (?_Orphan_all@_Container_base_secure@std@@QBEXXZ) already defined in Core.obj msvcprtd.lib

Error   9   error LNK2005: "public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (??1_Container_base_secure@std@@QAE@XZ) already defined in Core.obj  msvcprtd.lib

Error   10  error LNK2005: "public: __thiscall std::_Container_base_secure::_Container_base_secure(void)" (??0_Container_base_secure@std@@QAE@XZ) already defined in Core.obj   msvcprtd.lib

Error   11  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=(char const *)" (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in libcpmtd.lib(locale0.obj)  msvcprtd.lib

Error   12  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> >(unsigned int,char)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ID@Z) already defined in Serialization.obj  msvcprtd.lib

Error   13  error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::size(void)const " (?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in Core.obj    msvcprtd.lib

Error   14  error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in Serialization.obj    msvcprtd.lib

Error   15  error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in Serialization.obj   msvcprtd.lib

Error   16  error LNK2005: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in Serialization.obj    msvcprtd.lib

Error   17  error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in Core.obj   msvcprtd.lib

Error   18  error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)    MSVCRTD.lib

Error   19  error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)    MSVCRTD.lib

Error   20  error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)    MSVCRTD.lib

Error   21  error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj) MSVCRTD.lib

Error   22  error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMTD.lib(stdexcpt.obj)   MSVCRTD.lib

Error   23  error LNK2005: _strchr already defined in LIBCMTD.lib(strchr.obj)   MSVCRTD.lib

Error   24  error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)   MSVCRTD.lib

Error   25  error LNK2005: __CrtDbgReportW already defined in LIBCMTD.lib(dbgrptw.obj)  
MSVCRTD.lib

Error   26  error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)    MSVCRTD.lib

Error   27  error LNK2005: _memmove_s already defined in LIBCMTD.lib(memmove_s.obj) MSVCRTD.lib

Error   28  error LNK2005: _sprintf already defined in LIBCMTD.lib(sprintf.obj) MSVCRTD.lib

Error   29  error LNK2005: _sprintf_s already defined in LIBCMTD.lib(sprintf.obj)   MSVCRTD.lib

Error   30  error LNK2005: _strpbrk already defined in LIBCMTD.lib(strpbrk.obj) MSVCRTD.lib

Error   31  error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)  MSVCRTD.lib

Error   32  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)    MSVCRTD.lib

Warning 33  warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library   Afterfuture Game Engine

Error   34  fatal error LNK1169: one or more multiply defined symbols found C:\Users\Blake\Desktop\Afterfuture\Afterfuture Game Engine\Debug\Afterfuture Game Engine.exe
1个回答

3
问题在于你正在链接同一库的两个不同版本。如果一个库被静态链接到了标准C库的debug、单线程版本,那么使用该库的应用程序就不能动态链接到相同运行时库的release、多线程版本。
否则,你最终会拥有,例如,两个不同的内存分配器,而且如果从其中一个分配了内存但返回给了另一个,则可能会出现混乱。因此,即使链接器允许你这样做,应用程序也无法与该库安全地交互,那么这样做的意义是什么?
假设库已经被静态链接到标准C库的多线程版本,并且应用程序动态链接到单线程版本。如果库在对象上调用delete操作,而该对象是由应用程序分配的,并且库的分配器必须释放一个从未分配过的对象,会发生什么?!
没有可靠的方法使这个工作正常运行。要么将所有内容静态链接到完全相同的静态库中,要么动态链接所有内容。(这基本上是首选动态链接的原因。否则,必须同时链接所有库和应用程序或者非常小心。)你可以幸运地得到符号冲突警告。

你是在问修复这个静态库有什么意义吗?我能够修复源代码。 - James Linden
我并没有看到这如何回答我的问题,感谢您的考虑,但我只是在寻找调试用于构建静态库的源代码的方法。我有两个项目,一个项目是我的主可执行文件,另一个是我的静态库(正在被我的可执行项目使用)。 - James Linden
@Aux 给我们更多的细节。你将库链接到哪个运行时库?是静态还是动态?你将应用程序链接到哪个运行时库?是静态还是动态? - David Schwartz
我相信静态库正在链接到LIBCMTD.lib。 - James Linden
所有的东西都是用相同版本的VC编译的吗? - David Schwartz
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接