PDA

View Full Version : LNK2005 error in VS2005 when statically building Qt App


pkloc
10th July 2007, 23:08
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::operator=(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\assign_ 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?

jpn
11th July 2007, 06:52
Try following the instructions in our wiki: Building static applications (http://wiki.qtcentre.org/index.php?title=Building_static_applications).

pkloc
11th July 2007, 18:26
Are you saying it is necessary to build Qt itself statically in order to build a static application using Qt?

jpn
11th July 2007, 18:49
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.

pkloc
11th July 2007, 20:04
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)

pkloc
11th July 2007, 20:54
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!!!

jpn
12th July 2007, 15:56
Please correct me if I'm wrong but I don't think you need imports/exports with static libraries.

pkloc
12th July 2007, 19:02
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/knowledgebase/faq.2007-03-15.4154694947/

jpn
12th July 2007, 19:17
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.