The VC runtime version is different resulting in a link. lib Static library A case study and summary of duplicate definition problems occurred

Source: Internet
Author: User
Tags flush locale static class traits vc runtime
BackgroundThe Lib for link in different configurations is described in MSDN: C Runtime Library :
Switch the corresponding library version
/md MSVCRT. Lib Release version of Multithreaded DLLs
/MDd Msvcrtd. Lib Debug version of Multithreaded DLLs
/mt LIBCMT. Lib Release version of multithreaded static link
/MTd Libcmtd. Lib Debug version of multithreaded static links
/clr MSVCMRT. Lib Managed and unmanaged code blending
/clr:pure Msvcurt. Lib Pure managed Code
C + + standard Library :
Switch the corresponding library version
/md Msvcprt. Lib Release version of Multithreaded DLLs
/MDd Msvcprtd. Lib Debug version of Multithreaded DLLs
/mt Libcpmt. Lib Release version of multithreaded static link
/MTd Libcpmtd. Lib Debug version of multithreaded static links
The compiler automatically selects the corresponding LIB file according to the compilation options. In general, this does not occur. However, in some cases, once the various parts of your program (LIB, OBJ ... is not compiled by the same compilation options, and link together, there will be a variety of seemingly difficult to solve problems, such problems are mainly in the form of repeated definitions of errors, the usual solution is simple, is to choose the same compilation option to compile and then link. Case StudyI've just downloaded ANTLR and found the following build error when I was ready to compile its example (I created a VS project for this example, which is currently configured as a dynamic Link runtime library, debug version):
1>msvcprtd.lib (MSVCP80D.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 Antlr.lib (charscanner.obj ) 1>msvcprtd.lib (MSVCP80D.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> >::replace (unsigned int,unsigned int,char const *,unsigned INT ) "(? replace@? $basic _string@du? $char _traits@d@std@@v? $allocator @d@2@ @std @ @QAEAAV12 @iipbdi@z) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:void __thiscall std::basic_string <char,struct std::char_traits<Char>,class std::allocator<char> >::reserve (unsigned int) "(? reserve@? $basic _string@du? $char _ Traits@d@std@@v? $allocator @d@2@ @std @ @QAEXI @z) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib ( MSVCP80D.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 Antlr.lib (charscanner.obj) 1>msvcprtd.lib ( MSVCP80D.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 &) "(?? Y? $basic _string@du $char _traits@d@std@@v $allocator @d@2@ @std@ @QAEAAV01 @abv01@@z) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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 Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:char const & __thiscall std::basic_string <char,struct std::char_traits<char>,class std::allocator<char> >::operator[] (unsigned int) const " (?? A? $basic _string@du $char _traits@d@std@@v? $allocator @d@2@ @std @ @QBEABDI @z) already defined in Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:class std::basic_string&Lt;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 Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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 Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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 Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Class Std::basic_string<char,struct Std::char_ Traits<char>,class std::allocator<char> > __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 &) "(?? $? HDU $char _traits@d@std@@v? $allocator @d@1@ @std @ @YA? AV? $basic _string@du $char _traits@d@std@@v $allocator @d@2@@0@abv10@0@z) already defined in Antlr.lib ( Mismatchedcharexception.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:char const * __thiscall std::basic_string<char,struct std::char_traits<char& Gt;,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 Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): 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 &) "(?? $? MDU $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) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: " Public:class std::basic_ostream<char,struct Std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<< (class Std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*) (class std::basic_ostream< Char,struct std::char_traits<char> > &) "(?? 6. $basic _ostream@du? $char _traits@d@std@@ zzfcthotfixz @ @QAEAAV01 @p6aaav01@aav01@@z@z) already defined in Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:class std::basic_ostream<char,struct std ::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char>;: :operator<< (int) "(?? 6. $basic _ostream@du? $char _traits@d@std@@ zzfcthotfixz @ @QAEAAV01 @h@z) already defined in Antlr.lib (charscanner.obj) 1> Msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Class Std::basic_ostream<char,struct std::char_traits<char> > & __cdecl Std::endl (class Std::basic_ostream<char,struct std::char_traits<char> > &) "(? endl@std@@YAAAV $basic _ostream@du? $char _traits@d@std@@@1@aav21@@z) already defined in Antlr.lib (charscanner.obj) 1> Msvcprtd.lib (MSVCP80D.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@@ zzfcthotfixz @ @QAEXH_N @z) already Defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:int __thiscall Std::ios_ Base::width (int) "(? width@ios_base@std@ @QAEHH @z) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib ( MSVCP80D.dll): Error LNK2005: "Public:int __thiscall std::basic_streambuf<char,struct Std::char_traits<char > >::sputn (char const *,int) "(? sputn@? $basic _streambuf@du? $char _traits@d@std@@ zzfcthotfixz @ @QAEHPBDH @z) already Defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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 Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:static int __cdecl std::char_traits<char>::eof (void)" (? eof@? $char _traits@d@std@ @SAHXZ) Already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:int __thiscall St D::basic_streambuf<char,struct std::char_traits<char> &GT;::SPUTC (char) "(? sputc@? $basic _streambuf@du?$ char_traits@d@std@@ zzfcthotfixz @ @QAEHD @z) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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@@ zzfcthotfixz @ @QBEPAV? $basic _streambuf@du $char _TRAITS@D@STD@@@2@XZ) already defined in Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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@@ ZZFCTHOTFIXZ @ @QBEDXZ) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:int __thiscall std::ios_base::flags (void) const" (? flags@ios_base@std@ @QBEHXZ) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:int __thiscall std::ios_base:: width (void) const "(? width@ios_base@std@ @QBEHXZ) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib ( MSVCP80D.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 Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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@@ zzfcthotfixz @ @QAEAAV12 @xz) already defined in Antlr.lib (charscanner.obj) 1 >msvcprtd.lib (MSVCP80D.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@@ zzfcthotfixz @ @QBEPAV? $basic _ostream@du? $char _traits@d@std@@@2@xz) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Public:bool __thiscall std::ios_base:: Good (void) const "(? good@ios_base@std@ @QBE_NXZ) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib ( MSVCP80D.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@@ zzfcthotfixz @ @QAEXXZ) already defined in Antlr.lib ( Charscanner.obj) 1>msvcprtd.lib (MSVCP80D.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@@ zzfcthotfixz @ @QAEXXZ) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib ( MSVCP80D.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@@ zzfcthotfixz @ @QAEXXZ) already defined in Antlr.lib (charscanner.obj) 1>msvcprtd.lib (MSVCP80D.dll): Error LNK2005: "Class Std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char> Class Std::allocator<char> > (Class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct Std::char_traits<char>,class std::allocator<char> > Const &) "(?? $?6du $char _traits@d@std@@v? $allocator @d@1@ @std @ @YAAAV $basic _ostream@du? $char _traitS@d@std@@@0@aav10@abv? $basic _string@du? $char _traits@d@std@@v? $allocator @d@2@@0@@z) already defined in Antlr.lib ( Llkparser.obj) 1>libcpmt.lib (locale0.obj): Error LNK2005: "Private:static class Std::locale::_locimp * __cdecl std:: Locale::_getgloballocale (void) "(? _getgloballocale@locale@std@ @CAPAV_Locimp @12@xz) already defined in Msvcprtd.lib ( MSVCP80D.dll) 1>libcpmt.lib (locale0.obj): Error LNK2005: "private:static void __cdecl std::locale::facet::facet_ Register (class Std::locale::facet *) "(? facet_register@facet@locale@std@ @CAXPAV123 @@z) already defined in Msvcprtd.lib (MSVCP80D.dll) 1>libcpmt.lib (locale0.obj): Error LNK2005: "public:static void __cdecl std::_locinfo::_ Locinfo_dtor (class Std::_locinfo *) "(? _locinfo_dtor@_locinfo@std@ @SAXPAV12 @@z) already defined in Msvcprtd.lib ( MSVCP80D.dll) 1>libcpmt.lib (locale0.obj): Error LNK2005: "Public:static void __cdecl std::_locinfo::_locinfo_ctor ( Class Std::_locinfo *,char const *) "(? _locinfo_ctor@_locinfo@std@ @SAXPAV12 @pbd@z) already defined in Msvcprtd.lib (MSVCP80D.dll) 1>libcpmt.lib (xmutex.obj): Error LNK2005: "Public:void __thiscall S Td::_mutex::_lock (void) "(? _lock@_mutex@std@ @QAEXXZ) already defined in Msvcprtd.lib (MSVCP80D.dll) 1>libcpmt.lib ( Xmutex.obj): Error LNK2005: "Public:void __thiscall std::_mutex::_unlock (void)" (? _unlock@_mutex@std@ @QAEXXZ) already Defined in Msvcprtd.lib (MSVCP80D.dll) 1>libcpmt.lib (xlock.obj): Error LNK2005: ' Public: __thiscall std::_lockit::_ Lockit (int) "(?? 0_lockit@std@ @QAE @h@z) already defined in Msvcprtd.lib (MSVCP80D.dll) 1>libcpmt.lib (xlock.obj): Error LNK2005: " Public: __thiscall std::_lockit::~_lockit (void) "(?? 1_lockit@std@ @QAE @xz) already defined in Msvcprtd.lib (MSVCP80D.dll) 1>libcmt.lib (invarg.obj): Error LNK2005: __ Invoke_watson already defined in MSVCRTD.lib (MSVCR80D.dll) 1>libcmt.lib (invarg.obj): Error LNK2005: __invalid_ parameter already defined in MSVCRTD.lib (MSVCR80D.dll) 1>libcmt.lib (setlocal.obj): Error LNK2005: __configthReadlocale already defined in MSVCRTD.lib (MSVCR80D.dll) 1>libcmt.lib (tidtable.obj): Error LNK2005: __encode_pointer Already defined in MSVCRTD.lib (MSVCR80D.dll) 1>libcmt.lib (tidtable.obj): Error LNK2005: __decode_pointer already Defined in MSVCRTD.lib (MSVCR80D.dll) 1>libcmt.lib (tolower.obj): Error LNK2005: _tolower already defined in Msvcrtd.li B (MSVCR80D.dll)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.