CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    9

    Getting error LNK 2005

    Hi

    I am trying to compile the project with multiple .dll . One is for data collection and the other is openGL based. I am currently using VS2008 and fairly new to it. The code runs when my project properties -> Configuration Properties ->Code Generation -> Run time library -> Multi-threaded DLL. I am trying to make the project such that it works on a machine which doesn't have a VC++ compiler. So I am trying to compile the project with properties -> Configuration Properties ->Code Generation -> Run time library -> Multi-threaded Debug.

    But I get the following errors:

    1>Linking...
    1>msvcprtd.lib(MSVCP90D.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 Main.obj
    1>msvcprtd.lib(MSVCP90D.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> >:perator=(char const *)" (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in Main.obj
    1>msvcprtd.lib(MSVCP90D.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 Main.obj
    1>msvcprtd.lib(MSVCP90D.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> >::insert(unsigned int,unsigned int,char)" (?insert@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@IID@Z) already defined in Main.obj
    1>msvcprtd.lib(MSVCP90D.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> >::erase(unsigned int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in Main.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >:perator[](unsigned int)" (??A?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAADI@Z) already defined in Main.obj
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMTD.lib(_file.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _atoi already defined in LIBCMTD.lib(atox.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _printf already defined in LIBCMTD.lib(printf.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _sprintf already defined in LIBCMTD.lib(sprintf.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fflush already defined in LIBCMTD.lib(fflush.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:perator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
    1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>Release/OGLGraph.exe : fatal error LNK1169: one or more multiply defined symbols found


    I don't know, if thats the reason the application not being portable enough.

    Thanking you in advance

    Best


    Adi

  2. #2
    Join Date
    Nov 2007
    Posts
    35

    Re: Getting error LNK 2005

    Change the compiler switch to /MT instead of /MD and you won't have the c run time library dependency. For the graphics stuff see about delay loading the .dll and add the lib to the command line list. This way if the OS is too old or doesn't have the dll you have a chance to check the OS version and display a message yourself instead of the compiler error message.

    (If anyone knows how to set all projects to use the /MT switch by default I'd like to know the trick. I have to remember to change this setting first thing every time I create another program.)

    You can use GetVersion() or GetVersionEx() to check OS version. Or you can explicitly try to load the graphics library dll with LoadLibrary() and GetProcAddress() if you want to do it old school. But that /MD switch is a "burn ya'" that I remember from back in vc++ 6.0. It's way embarrassing to have your code crap out as soon as it's run because of a run-time dll. Looks like they still don't let you change the default. Sheesh!!
    Last edited by MilesAhead; October 19th, 2010 at 02:18 PM.

  3. #3
    Join Date
    Oct 2010
    Posts
    9

    Re: Getting error LNK 2005

    Hi

    Thanks for the quick reply

    If i change my setting to /MT. I get additional errors in:

    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005

    I checked the loadlibrary() function, but it seems a little difficult for me to implement.

    I am also not able to understand why it works in /MD??

    Can I just go to ignore specific library option and ignore MSVCRTD.lib and msvcprtd.lib.

    I am already ignoring libcmtd.lib and it reduced my errors. As i think all these libraries are needed for debug mode and I am in release mode.

    Best

    adi

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Getting error LNK 2005

    Perhaps the DLLs were built with debug libraries?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured