Results 1 to 6 of 6

Thread: Link errors when linking chained libraries on windows

  1. #1
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Link errors when linking chained libraries on windows

    This isn't a question but a declaration of my own stupidity. If I can save you some hours of banging your head against the wall then I hope this helps.

    I'm using Qt 4.4.0 on Windows with MSVC 2008 Express, although I'm sure this could happen to anyone when compiling on windows.

    The problem happens when you have one library linking against another library. I use the following code to export classes on windows:

    Qt Code:
    1. #if defined(Q_OS_WIN32)
    2. # ifdef MYLIB
    3. # define MYEXPORT Q_DECL_EXPORT
    4. # else
    5. # define MYEXPORT Q_DECL_IMPORT
    6. # endif
    7. #else
    8. # define MYEXPORT
    9. #endif
    10.  
    11. class MYEXPORT myclass : public QObject {
    12. //...
    13. }
    To copy to clipboard, switch view to plain text mode 

    If I try to be sneaky and use the same MYEXPORT macro in both libraries and then try to link them together i get a mess of errors like this:

    Qt Code:
    1. cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DAXISLIB -DQT_DLL -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\qt\msvc\4.4.0\include\QtUiTools" -I"c:\qt\msvc\4.4.0\include\QtCore" -I"c:\qt\msvc\4.4.0\include\QtCore" -I"c:\qt\msvc\4.4.0\include\QtGui" -I"c:\qt\msvc\4.4.0\include\QtGui" -I"c:\qt\msvc\4.4.0\include\QtXml" -I"c:\qt\msvc\4.4.0\include\QtXml" -I"c:\qt\msvc\4.4.0\include\QtSql" -I"c:\qt\msvc\4.4.0\include\QtSql" -I"c:\qt\msvc\4.4.0\include" -I"..\libaxis" -I"c:\qt\msvc\4.4.0\include\ActiveQt" -I".tmp" -I"." -I"c:\qt\msvc\4.4.0\mkspecs\default" -Fo.tmp\ @C:\DOCUME~1\root\LOCALS~1\Temp\nm1648.tmpclientmodule.cpp
    2. link /LIBPATH:"c:\qt\msvc\4.4.0\lib" /NOLOGO /INCREMENTAL:NO /DLL /MANIFEST /MANIFESTFILE:".tmp\mylib.intermediate.manifest" /OUT:..\bin\mylib.dll @C:\DOCUME~1\root\LOCALS~1\Temp\nm1649.tmp
    3. Creating library ..\bin\mylib.lib and object ..\bin\mylib.exp
    4. clientmodule.obj : error LNK2019: unresolved external symbol "public: static struct QMetaObject const MyObject::staticMetaObject" (?staticMetaObject@MyObject@@2UQMetaObject@@B) referenced in function "public: static class QString __cdecl MyObject::tr(char const *,char const *)" (?tr@MyObject@@SA?AVQString@@PBD0@Z)
    5. clientmodule.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyObject::metaObject(void)const " (?metaObject@MyObject@@UBEPBUQMetaObject@@XZ)
    6. clientmodule.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyObject::qt_metacast(char const *)" (?qt_metacast@MyObject@@UAEPAXPBD@Z)
    7. clientmodule.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall MyObject::qt_metacall(enumQMetaObject::Call,int,void * *)" (?qt_metacall@MyObject@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
    8. ..\bin\mylib.dll : fatal error LNK1120: 4 unresolved externals
    9. NMAKE : fatal error U1077: 'C:\vs9\VC\BIN\link.EXE' : return code '0x460'
    10. Stop.
    11. NMAKE : fatal error U1077: 'C:\vs9\VC\BIN\nmake.exe' : return code '0x2'
    12. Stop.
    13. NMAKE : fatal error U1077: 'cd' : return code '0x2'
    14. Stop.
    To copy to clipboard, switch view to plain text mode 

    The reason is that when i compile my second library it includes the headers from the first library but the macro wants to export instead of import the classes. This seems to only happen with QObject classes but i could be wrong.

    So in the second library write a new macro with a DIFFERENT name. I sure hope this helps you.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    541
    Thanked 83 Times in 78 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Link errors when linking chained libraries on windows

    You're probably using MYLIB define for both libs. That's wrong. Use a more specific define to distinguish between the two libs.

    btw: no need to put a #ifdef Q_OS_WIN32 around - this works fine for Linux and others too

  3. #3
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Link errors when linking chained libraries on windows

    Yeah that's exactly what I was doing. Since I didn't find the info anywhere else on the web I figured I'd share it here.

    It seems like 90% of the bugs I run into are obvious forehead slappers.

  4. #4
    Join Date
    Apr 2008
    Location
    California
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Link errors when linking chained libraries on windows

    Hello,

    I didn't understand the solution very well here but I'm having the same issue that was discussed in this thread.

    My app is developed using QT 4.3.1 commerical/ VS 2005. Everything works great when build from VS 2005. Now I want to deploy/ distribute the app to other systems. So I did read the deploy document on trolltech and followed these steps:

    opened the QT command prompt...
    cmd> nmake clean (no errors)
    cmd> qmake -config release (no errors)
    cmd> nmake ---- lots of LNK2019 errors

    I'm copying partial error output here:
    Qt Code:
    1. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    2. blic: bool __thiscall QDomDocument::setContent(class QIODevice *,class QString *
    3. ,int *,int *)" (__imp_?setContent@QDomDocument@@QAE_NPAVQIODevice@@PAVQString@@P
    4. AH2@Z) referenced in function "private: void __thiscall snipit::checkOptions(voi
    5. d)" (?checkOptions@snipit@@AAEXXZ)
    6. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    7. blic: __thiscall QDomNode::~QDomNode(void)" (__imp_??1QDomNode@@QAE@XZ) referenc
    8. ed in function "private: void __thiscall snipit::checkOptions(void)" (?checkOpti
    9. ons@snipit@@AAEXXZ)
    10. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    11. blic: __thiscall QDomDocument::QDomDocument(class QString const &)" (__imp_??0QD
    12. omDocument@@QAE@ABVQString@@@Z) referenced in function "private: void __thiscall
    13. snipit::checkOptions(void)" (?checkOptions@snipit@@AAEXXZ)
    14. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    15. blic: class QDomNode __thiscall QDomNode::appendChild(class QDomNode const &)" (
    16. __imp_?appendChild@QDomNode@@QAE?AV1@ABV1@@Z) referenced in function "private: v
    17. oid __thiscall snipit::checkOptions(void)" (?checkOptions@snipit@@AAEXXZ)
    18. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    19. blic: class QDomElement __thiscall QDomDocument::createElement(class QString con
    20. st &)" (__imp_?createElement@QDomDocument@@QAE?AVQDomElement@@ABVQString@@@Z) re
    21. ferenced in function "private: void __thiscall snipit::checkOptions(void)" (?che
    22. ckOptions@snipit@@AAEXXZ)
    23. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    24. blic: class QString __thiscall QHttpResponseHeader::reasonPhrase(void)const " (_
    25. _imp_?reasonPhrase@QHttpResponseHeader@@QBE?AVQString@@XZ) referenced in functio
    26. n "private: void __thiscall snipit::readResponseHeaderFilePosted(class QHttpResp
    27. onseHeader const &)" (?readResponseHeaderFilePosted@snipit@@AAEXABVQHttpResponse
    28. Header@@@Z)
    29. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    30. blic: int __thiscall QHttpResponseHeader::statusCode(void)const " (__imp_?status
    31. Code@QHttpResponseHeader@@QBEHXZ) referenced in function "private: void __thisca
    32. ll snipit::readResponseHeaderFilePosted(class QHttpResponseHeader const &)" (?re
    33. adResponseHeaderFilePosted@snipit@@AAEXABVQHttpResponseHeader@@@Z)
    34. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    35. blic: class QDomElement __thiscall QDomNode::toElement(void)const " (__imp_?toEl
    36. ement@QDomNode@@QBE?AVQDomElement@@XZ) referenced in function "private: void __t
    37. hiscall snipit::readyReadFile(class QHttpResponseHeader const &)" (?readyReadFil
    38. e@snipit@@AAEXABVQHttpResponseHeader@@@Z)
    39. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    40. blic: class QDomNode __thiscall QDomNodeList::item(int)const " (__imp_?item@QDom
    41. NodeList@@QBE?AVQDomNode@@H@Z) referenced in function "private: void __thiscall
    42. snipit::readyReadFile(class QHttpResponseHeader const &)" (?readyReadFile@snipit
    43. @@AAEXABVQHttpResponseHeader@@@Z)
    44. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    45. blic: class QDomNodeList & __thiscall QDomNodeList::operator=(class QDomNodeList
    46. const &)" (__imp_??4QDomNodeList@@QAEAAV0@ABV0@@Z) referenced in function "priv
    47. ate: void __thiscall snipit::readyReadFile(class QHttpResponseHeader const &)" (
    48. ?readyReadFile@snipit@@AAEXABVQHttpResponseHeader@@@Z)
    49. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    50. blic: __thiscall QDomNodeList::~QDomNodeList(void)" (__imp_??1QDomNodeList@@QAE@
    51. XZ) referenced in function "private: void __thiscall snipit::readyReadFile(class
    52. QHttpResponseHeader const &)" (?readyReadFile@snipit@@AAEXABVQHttpResponseHeade
    53. r@@@Z)
    54. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    55. blic: unsigned int __thiscall QDomNodeList::length(void)const " (__imp_?length@Q
    56. DomNodeList@@QBEIXZ) referenced in function "private: void __thiscall snipit::re
    57. adyReadFile(class QHttpResponseHeader const &)" (?readyReadFile@snipit@@AAEXABVQ
    58. HttpResponseHeader@@@Z)
    59. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    60. blic: class QDomNodeList __thiscall QDomElement::elementsByTagName(class QString
    61. const &)const " (__imp_?elementsByTagName@QDomElement@@QBE?AVQDomNodeList@@ABVQ
    62. String@@@Z) referenced in function "private: void __thiscall snipit::readyReadFi
    63. le(class QHttpResponseHeader const &)" (?readyReadFile@snipit@@AAEXABVQHttpRespo
    64. nseHeader@@@Z)
    65. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    66. blic: __thiscall QDomNode::QDomNode(void)" (__imp_??0QDomNode@@QAE@XZ) reference
    67. d in function "private: void __thiscall snipit::readyReadFile(class QHttpRespons
    68. eHeader const &)" (?readyReadFile@snipit@@AAEXABVQHttpResponseHeader@@@Z)
    69. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    70. blic: __thiscall QDomNodeList::QDomNodeList(void)" (__imp_??0QDomNodeList@@QAE@X
    71. Z) referenced in function "private: void __thiscall snipit::readyReadFile(class
    72. QHttpResponseHeader const &)" (?readyReadFile@snipit@@AAEXABVQHttpResponseHeader
    73. @@@Z)
    74. snipit.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) pu
    75. blic: class QByteArray __thiscall QHttp::readAll(void)" (__imp_?readAll@QHttp@@Q
    76. AE?AVQByteArray@@XZ) referenced in function "private: void __thiscall snipit::re
    77. adyReadFile(class QHttpResponseHeader const &)" (?readyReadFile@snipit@@AAEXABVQ
    78. HttpResponseHeader@@@Z)
    79. release\snipit.exe : fatal error LNK1120: 40 unresolved externals
    80. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\l
    81. ink.EXE"' : return code '0x460'
    82. Stop.
    83. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\n
    84. make.exe"' : return code '0x2'
    85. Stop.
    To copy to clipboard, switch view to plain text mode 

    what am I doing wrong here or how can I resolve the issue I'm having?

    thanks in advance.
    - AR

  5. #5
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Link errors when linking chained libraries on windows

    It looks like a different problem then the one I posted about. It looks like you forgot to include the XML and Network modules in your .pro file.

    QT += xml \
    network

    You can tell this because your linker is missing the QDomDocument::setContent() and QHttpResponseHeader::reasonPhrase() methods amoong others.

  6. The following user says thank you to darkadept for this useful post:

    arunredi (26th May 2008)

  7. #6
    Join Date
    Apr 2008
    Location
    California
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Link errors when linking chained libraries on windows

    you were right. All those errors got resolved after adding the line into my .pro file. thank you.
    - AR

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.