Results 1 to 10 of 10

Thread: LNK2005 error in VS2005 when statically building Qt App

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default LNK2005 error in VS2005 when statically building Qt App

    Hello,

    I am building my app in Visual Studio 2005 and wish to link to static version of the CRT. To do this I go to my project properties and in Configuration Properties->c/c++->Code Generation I set Runtime Library = /MTd (Multi-threaded Debug). This gives me the following errors:

    Linking...
    9>MSVCRT.lib(MSVCR80.dll) : error LNK2005: _isupper already defined in LIBCMTD.lib(_ctype.obj)
    9>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 LIBCMTD.lib(typinfo.obj)
    9>MSVCRT.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)
    9> Creating library nrcs_imp.lib and object nrcs_imp.exp
    9>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
    9>LIBCMTD.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
    9>E:\projects\Assign\pkloc_AssignQT\edm_news\assig n_qt\qt\source\main\Debug\Assign.exe : fatal error LNK1169: one or more multiply defined symbols found


    When linking to dynamic version of CRT, by setting Runtime Library = /MDd (Multi-threaded Debug DLL) I get no errors.

    How can I fix this?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    Try following the instructions in our wiki: Building static applications.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    Are you saying it is necessary to build Qt itself statically in order to build a static application using Qt?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    Quote Originally Posted by pkloc View Post
    Are you saying it is necessary to build Qt itself statically in order to build a static application using Qt?
    Yes. Otherwise you'll get a conflict between C runtime libs. While your application links to static runtime (LIBCMTD.lib) Qt still links to dynamic runtime (MSVCRT.lib). That's what the error message above is trying to tell.
    J-P Nurmi

  5. #5
    Join Date
    Mar 2007
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    I built the static version of Qt, then I cleaned and re-built my project and now I get the following linker errors:

    Linking...
    1> Creating library E:\projects\Assign\pkloc_AssignQT\edm_news\assign_ qt\qt\source\main\Debug\common.lib and object E:\projects\Assign\pkloc_AssignQT\edm_news\assign_ qt\qt\source\main\Debug\common.exp
    1>AvidStyle.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QHeaderView::staticMetaObject" (?staticMetaObject@QHeaderView@@2UQMetaObject@@B)
    1>AvidStyle.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QMenuBar::staticMetaObject" (?staticMetaObject@QMenuBar@@2UQMetaObject@@B)
    1>AvidStyle.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QScrollArea::staticMetaObject" (?staticMetaObject@QScrollArea@@2UQMetaObject@@B)
    1>moc_AlternateScrollArea.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QScrollArea::staticMetaObject" (?staticMetaObject@QScrollArea@@2UQMetaObject@@B)

  6. #6
    Join Date
    Mar 2007
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    OK, so I changed a setting for all the libraries I'm building: I changed Configuration Type from Dynamic Library to Static Library. That took care of the errors in the previous posting. Now, unfortunately, when my main project starts to link I get the following:

    A bunch of wnarnings like:

    1>NRCSModel.lib(CacheModel.obj) : warning LNK4049: locally defined symbol ?convertToQString@JavaQTBridgeHelper@javahelper@av id@@SA?AVQString@@VString@lang@java@@@Z (public: static class QString __cdecl avid::javahelper::JavaQTBridgeHelper::convertToQSt ring(class java::lang::String)) imported
    1>NRCSModel.lib(EntityShell.obj) : warning LNK4049: locally defined symbol ?convertToQString@JavaQTBridgeHelper@javahelper@av id@@SA?AVQString@@VString@lang@java@@@Z (public: static class QString __cdecl avid::javahelper::JavaQTBridgeHelper::convertToQSt ring(class java::lang::String)) imported
    1>EventDatesModel.obj : warning LNK4049: locally defined symbol ??0UIException@ui@avid@@QAE@ABVQString@@@Z (public: __thiscall avid::ui::UIException::UIException(class QString const &)) imported


    followed by a bunch of errors like:

    1>ConditionDateCoverageEvent.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: void __thiscall avid::javahelper::Loggable::logCodeLine(class QString const &)const " (__imp_?logCodeLine@Loggable@javahelper@avid@@IBEX ABVQString@@@Z)
    1>ConditionDateCoverageLocation.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: void __thiscall avid::javahelper::Loggable::logCodeLine(class QString const &)const " (__imp_?logCodeLine@Loggable@javahelper@avid@@IBEX ABVQString@@@Z)


    Ouch!!!

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    Please correct me if I'm wrong but I don't think you need imports/exports with static libraries.
    J-P Nurmi

  8. #8
    Join Date
    Mar 2007
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    That's true, thank you.

    Ultimately I am trying to link to the static version of the CRT but I guess that is not supported by Qt according to this:

    http://trolltech.com/developer/knowl...15.4154694947/

  9. The following user says thank you to pkloc for this useful post:

    jpn (12th July 2007)

  10. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: LNK2005 error in VS2005 when statically building Qt App

    Hey, thanks for pointing it out! I just wish they were more specific about the memory problems. I have added a notice to our wiki about the issue.
    J-P Nurmi

  11. #10
    Join Date
    Apr 2011
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: LNK2005 error in VS2005 when statically building Qt App


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.