Results 1 to 3 of 3

Thread: QMake - Linking to Static Libraries (win32-msvc2008) - Unresolved Externals

  1. #1
    Join Date
    Oct 2009
    Posts
    3
    Thanked 3 Times in 1 Post
    Platforms
    Windows

    Default QMake - Linking to Static Libraries (win32-msvc2008) - Unresolved Externals

    As a preface: I have compiled Qt statically with the win32-msvc2008 compiler using both the "-O1 -MD" and "-O1 -MT" compiler flags.

    In Qt Creator, I wanted to create a simple Win32 DLL that statically linked to Qt:

    Qt Code:
    1. // main.cpp
    2. #include <QtCore/QString>
    3. #include <QtCore/QtDebug>
    4. #include "windows.h"
    5.  
    6. bool WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
    7. QString temp("This is a QString");
    8. qDebug() << temp;
    9. return true;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I then used the following .pro file:

    Qt Code:
    1. // test.pro
    2. QT -= gui
    3. TARGET = test
    4. TEMPLATE = lib
    5. CONFIG += dll
    6. DEFINES += TEST_LIBRARY
    7. SOURCES += main.cpp
    8. HEADERS +=
    To copy to clipboard, switch view to plain text mode 

    However, the Qt libraries are not correctly linked (unresolved externals). See the following build output:

    Qt Code:
    1. Starting: G:/dev/libraries/vendor/nokia/Qt/4.5.3/msvc2008-static/bin/qmake.exe G:/dev/sandbox/test/test.pro -spec win32-msvc2008 -r
    2. Exited with code 0.
    3. Starting: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/BIN/nmake.exe
    4. "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe" -f Makefile.Release
    5. cl -c -nologo -Zm200 -Zc:wchar_t- -O1 -MD -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT \
    6. -DTEST_LIBRARY -DQT_DLL -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT \
    7. -I"..\..\libraries\vendor\nokia\Qt\4.5.3\msvc2008-static\include\QtCore" \
    8. -I"..\..\libraries\vendor\nokia\Qt\4.5.3\msvc2008-static\include" \
    9. -I"..\..\libraries\vendor\nokia\Qt\4.5.3\msvc2008-static\include\ActiveQt" \
    10. -I"release" -I"..\..\libraries\vendor\nokia\Qt\4.5.3\msvc2008-static\mkspecs\win32-msvc2008" \
    11. -Forelease\ @C:\Users\Steven\AppData\Local\Temp\nm111.tmp
    12. main.cpp
    13.  
    14. link /LIBPATH:"g:\dev\libraries\vendor\nokia\Qt\4.5.3\msvc2008-static\lib" /NOLOGO /INCREMENTAL:NO /DLL /OUT:release\test.dll @C:\Users\Steven\AppData\Local\Temp\nm44D.tmp
    15. main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::~QString(void)" (__imp_??1QString@@QAE@XZ) referenced in function _DllMain@12
    16. main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QDebug::~QDebug(void)" (__imp_??1QDebug@@QAE@XZ) referenced in function _DllMain@12
    17. main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QDebug & __thiscall QDebug::operator<<(class QString const &)" (__imp_??6QDebug@@QAEAAV0@ABVQString@@@Z) referenced in function _DllMain@12
    18. main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class QDebug __cdecl qDebug(void)" (__imp_?qDebug@@YA?AVQDebug@@XZ) referenced in function _DllMain@12
    19. main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private: static struct QString::Data * __cdecl QString::fromAscii_helper(char const *,int)" (__imp_?fromAscii_helper@QString@@CAPAUData@1@PBDH@Z) referenced in function _DllMain@12
    20. release\test.dll : fatal error LNK1120: 5 unresolved externals
    To copy to clipboard, switch view to plain text mode 

    I have checked the .tmp files and QtCore.lib is indeed included in the nmake command--this baffles me. Compiling the test project in Visual Studio 2008 correctly links to the Qt static libraries.

    Does anyone know what might be causing the problem and how I can go about fixing it?

  2. #2
    Join Date
    Oct 2009
    Posts
    3
    Thanked 3 Times in 1 Post
    Platforms
    Windows

    Default Re: QMake - Linking to Static Libraries (win32-msvc2008) - Unresolved Externals

    bump

    Does anyone have any ideas?

  3. #3
    Join Date
    Oct 2009
    Posts
    3
    Thanked 3 Times in 1 Post
    Platforms
    Windows

    Default Re: QMake - Linking to Static Libraries (win32-msvc2008) - Unresolved Externals

    After doing extensive tests by compiling and linking the app manually on the command line and adding/removing arguments, I believe I found the problem. The unresolved externals link errors occur when QT_DLL is defined.

    The solution is to define QT_NODLL in your .pro (DEFINES += QT_NODLL), as qmake automatically inserts -DQT_DLL when QT_NODLL is not defined (see mkspecs/features/qt.prf).

  4. The following 3 users say thank you to snapcall for this useful post:

    Candlelightdoener (2nd December 2010), CtrlBrk (8th December 2010), t_3 (17th August 2015)

Similar Threads

  1. shared vs static
    By alisami in forum Installation and Deployment
    Replies: 3
    Last Post: 4th October 2008, 13:04
  2. Replies: 16
    Last Post: 23rd May 2008, 10:12
  3. Win32 qmake: building a static library
    By Amanda in forum Qt Programming
    Replies: 5
    Last Post: 8th November 2006, 19:32

Tags for this Thread

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.