链接静态库的问题

Problems with linking static libraries

本文关键字:问题 静态 链接      更新时间:2023-10-16

有一个主项目是用VC2008写的,我不能改变它。我想写一个LIB文件,我想在那个项目中使用。

我想在VS2013中编写这个LIB文件,但我认为这将是不兼容的。这就是为什么我试图用VS2008工具集编译它(是的,我已经安装了它,但我不想使用那个IDE)。

所以,都在一个:主要项目:VS2008LIB项目:VS2008 Toolset from 2013

当我在2008年IDE中编译我的LIB时,它与我的主要项目完美地工作,但如果我从2013年编译它,使用工具集我无法编译主要项目,因为以下错误:

1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _sprintf already defined in LIBCMT.lib(sprintf.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _strstr already defined in LIBCMT.lib(strstr.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _strchr already defined in LIBCMT.lib(strchr.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _system already defined in LIBCMT.lib(system.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _vsprintf_s already defined in LIBCMT.lib(vsnprnc.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _tolower already defined in LIBCMT.lib(tolower.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _fopen already defined in LIBCMT.lib(fopen.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: __strdup already defined in LIBCMT.lib(strdup.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _fwrite already defined in LIBCMT.lib(fwrite.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _freopen already defined in LIBCMT.lib(freopen.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _strcat_s already defined in LIBCMT.lib(strcat_s.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _fclose already defined in LIBCMT.lib(fclose.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmt.lib(uncaught.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "protected: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Myptr(void)const " (?_Myptr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IBEPBDXZ) already defined in InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::rfind(char const *,unsigned int,unsigned int)const " (?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z) already defined in gamelib.lib(ActorInstanceData.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : 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 cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::~basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >(void)" (??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ) already defined in eterlib.lib(GrpTextInstance.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV01@@Z) already defined in eterlib.lib(GrpTextInstance.obj)
1>msvcprt.lib(MSVCP90.dll) : 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> >::substr(unsigned int,unsigned int)const " (?substr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV12@II@Z) already defined in PythonSkill.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::find_last_of(char const *,unsigned int)const " (?find_last_of@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDI@Z) already defined in PythonSkill.obj
1>msvcprt.lib(MSVCP90.dll) : 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 InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::length(void)const " (?length@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : 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 InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::_String_iterator<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::end(void)" (?end@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE?AV?$_String_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in MovieMan.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::_String_iterator<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::begin(void)" (?begin@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE?AV?$_String_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in MovieMan.obj
1>msvcprt.lib(MSVCP90.dll) : 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 *)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in InstanceBaseEffect.obj
1>msvcprt.lib(MSVCP90.dll) : 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 InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : 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) already defined in InstanceBaseEffect.obj
1>msvcprt.lib(MSVCP90.dll) : 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 InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : 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 InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : 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 InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : 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)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in eterpack.lib(EterPack.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in eterpack.lib(EterPack.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in eterpack.lib(EterPack.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in eterpack.lib(EterPack.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall std::ios_base::rdstate(void)const " (?rdstate@ios_base@std@@QBEHXZ) already defined in eterpack.lib(EterPack.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : 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 cryptlib-5.6.1MT.lib(integer.obj)
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in InstanceBase.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static int __cdecl std::char_traits<char>::compare(char const *,char const *,unsigned int)" (?compare@?$char_traits@D@std@@SAHPBD0I@Z) already defined in InstanceBaseEffect.obj
1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq(char const &,char const &)" (?eq@?$char_traits@D@std@@SA_NABD0@Z) already defined in gamelib.lib(ActorInstanceData.obj)
1>LIBCMT.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Release/metin2client.exe : fatal error LNK1169: one or more multiply defined symbols found

我不知道这些错误信息是什么意思(好吧,可能VS2013也包括基本函数,这是VS2008的一部分,但为什么?如何解决?)。

有没有人可以帮助我,我该如何解决这个错误?

谢谢!

回复者:Joachim Pileborg忘记将LIB设置为多线程而不是多线程DLL。谢谢你。

看起来您的库已经击中了#pragma comment(lib,"msvcp90.lib"),可以用/nodefaultlib链接器选项来对抗,但是随后您可能必须提供要链接的库列表