none
LNK2005 errors with LIBCMTD.lib and MSVCRTD.lib

    Question

  • Hi people!

    I've got issues when trying to compile an opensource game (SuperTuxKart).

    I work on VC9 (Visual C++ 2008) on Vista.

    The errors I get are:
    1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __aligned_malloc already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __aligned_free already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(setlocal.obj) : error LNK2005: _setlocale already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(sprintf.obj) : error LNK2005: _sprintf already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(vsprintf.obj) : error LNK2005: _vsprintf already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)
    1>LIBCMTD.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dbgrptw.obj) : error LNK2005: __CrtDbgReportW already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(printf.obj) : error LNK2005: _printf already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(getenv.obj) : error LNK2005: _getenv already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(strtol.obj) : error LNK2005: _strtol already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(_file.obj) : error LNK2005: ___iob_func already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(fflush.obj) : error LNK2005: _fflush already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>./../../../supertuxkart_d.exe : fatal error LNK1169: one or more multiply defined symbols found



    I saw on some forum that it was due to the Runtime Library. I then changed the latter from "Multi-threaded Debug DLL" to "Multi-threaded Debug". The errors I then got were:
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __wassert already defined in LIBCMTD.lib(wassert.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __aligned_malloc already defined in LIBCMTD.lib(dbgheap.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __aligned_free already defined in LIBCMTD.lib(dbgheap.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _sprintf already defined in LIBCMTD.lib(sprintf.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _printf already defined in LIBCMTD.lib(printf.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _strncpy already defined in LIBCMTD.lib(strncpy.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _perror already defined in LIBCMTD.lib(perror.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _abort already defined in LIBCMTD.lib(abort.obj)
    1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
    1>MSVCRTD.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 LIBCMTD.lib(typinfo.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _isspace already defined in LIBCMTD.lib(_ctype.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMTD.lib(_file.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fopen already defined in LIBCMTD.lib(fopen.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fgetc already defined in LIBCMTD.lib(fgetc.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _setvbuf already defined in LIBCMTD.lib(setvbuf.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _freopen already defined in LIBCMTD.lib(freopen.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _exit already defined in LIBCMTD.lib(crt0dat.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _strrchr already defined in LIBCMTD.lib(strrchr.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _atoi already defined in LIBCMTD.lib(atox.obj)
    1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>./../../../supertuxkart_d.exe : fatal error LNK1169: one or more multiply defined symbols found


    What could I do to solve that problem?...

    Cheers in advance,

    Julien.

    Thursday, August 19, 2010 1:56 PM

Answers

  • I finally managed to build the whole solution!

    The problem was actually due to the fact that I had compiled the PLIB library in Debug mode when it should obviously have been done in Release mode...

    So, everything is fine now. And can build and run it with no problems.

    Thank you very well for all your replies anyway. I've learned a few things about compilation in C++ thanks to you. So thank you again for your time.

    Cheers,

    Julien.

    • Marked as answer by Julien LP Saturday, August 21, 2010 9:54 AM
    Saturday, August 21, 2010 9:52 AM

All replies

  • It looks like you have a mixture of /MT and /MD in your solution.  You must make them one or the other (or possibly /ML).

    Start by deciding which of /MT or /MD you want;  then look at the Code Generation/Runtime Library property for each project and make sure it matches.

    If this still fails to link, then it means one or more of the File has overridden this property at the file level, so you must then search for the offending file.

    See also http://support.microsoft.com/kb/154753/en-gb


    Answering policy: see profile.
    Thursday, August 19, 2010 2:06 PM
  • Thank you very much for your reply and the link.

    So, if I understand well (I'm totally new to C++), if I have 3 projects within my solution, the 3 of them should have the same Runtime Library (/MD, /MT or one of the others)? The Runtime Library is only applicable to projects, not to each file I hope?

    I have tried to set /MD on all of them and build the solution but I had the same kind of errors and same for /MT to all, /MTd to all and /MDd to all.

    I forgot to mention that the solution is using that option when compiling: /NODEFAULTLIB:"libcmt.lib". Why is that?

    Thank you for your help! :D

    Thursday, August 19, 2010 7:13 PM
  • if I have 3 projects within my solution, the 3 of them should have the same Runtime Library (/MD, /MT or one of the others)? The Runtime Library is only applicable to projects, not to each file I hope?

    The choice of runtime library affects the object code of each source file, and must be consistent for all files in an application.  This includes any third-party libraries you are using.

    Usually the choice of runtime library for a file is inherited from the project it belongs to, but this can be (mistakenly) overridden at the source file level.

    I have tried to set /MD on all of them and build the solution but I had the same kind of errors and same for /MT to all, /MTd to all and /MDd to all.

    The /MDd is the debug-build version of /MD.  Assuming you have chosen to use /MD, your Debug configuration should be specifying /MDd and your Release configuration /MD.

    Are you linking any additional libraries which you haven't built (other than the standard Microsoft ones, I mean) ?  If so, these may determine which runtime library you must use.  If you have two of these requiring different runtime libraries, you are in trouble!

    I forgot to mention that the solution is using that option when compiling: /NODEFAULTLIB:"libcmt.lib". Why is that?

    You shouldn't normally need this unless you are trying to force a particular runtime library (this one tells the library to ignore any requests embedded in the objects for libcmt.lib).  Whether it's appropriate depends on any additional libraries I referred to above.  Leave it there for the time being, but it may be instructive to see what happens if you take that out.
    Answering policy: see profile.
    Thursday, August 19, 2010 8:53 PM
  • Hmmm... Ok, I suppose it makes sense.

    Although, how do I know which runtime library each "external libraries" uses?

    As I said, the project is an open source game and it is quite big. It needs loads of libraries such as GLUT, PLIB, SDL, OpenAL and OpenGL.

    Apparently it should build without errors as it is but it doesn't! :/ Can also come from the versions of those libraries that I installed? Can runtime libraries be different from one version to another?...

    Thank you very much for you help!

    Thursday, August 19, 2010 9:18 PM
  • It needs loads of libraries such as GLUT, PLIB, SDL, OpenAL and OpenGL.

    Well, these must also obey the single runtime library requirement, if necessary by force! (By force, I mean by use of /NODEFAULTLIB )

    Those libraries will probably have been created with a particular runtime library in mind. 

    I've taken a moment to review your original post for this, and think that you may be able to address your problems by adding libcmtd.lib to your "Ignore Specific Library" list.


    Answering policy: see profile.
    Friday, August 20, 2010 10:17 AM
  • I finally managed to build the whole solution!

    The problem was actually due to the fact that I had compiled the PLIB library in Debug mode when it should obviously have been done in Release mode...

    So, everything is fine now. And can build and run it with no problems.

    Thank you very well for all your replies anyway. I've learned a few things about compilation in C++ thanks to you. So thank you again for your time.

    Cheers,

    Julien.

    • Marked as answer by Julien LP Saturday, August 21, 2010 9:54 AM
    Saturday, August 21, 2010 9:52 AM
  • This will help some of the readers who<s issue is not quite the same but ended up here anyway. read the links below. the same problem occured with visual studio 2015 with the advent of windows sdk 10 which brings up libucrt. ucrt is the windows implementation of  C Runtime (CRT) aka the posix runtime library.  You most likely have code that was ported from unix... Welcome to the drawback


    https://support.microsoft.com/en-us/help/148652/a-lnk2005-error-occurs-when-the-crt-library-and-mfc-libraries-are-linked-in-the-wrong-order-in-visual-c

    https://github.com/lordmulder/libsndfile-MSVC/blob/master/src/sf_unistd.h

    https://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00224.html

    https://msdn.microsoft.com/en-us/library/y23kc048.aspx

    https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/


    Sunday, June 25, 2017 11:49 AM