Results 1 to 13 of 13

Thread: [MSVC 2010] Static linking and unresolved external symbols

  1. #1
    Join Date
    Aug 2012
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [MSVC 2010] Static linking and unresolved external symbols

    Just few minutes ago i have build static libraries for Qt using:

    Qt Code:
    1. configure -no-webkit -no-scripttools -qt-sql-mysql -fast -opensource -static -platform win32-msvc2010
    To copy to clipboard, switch view to plain text mode 

    Everything worked perfectly fine. Later i tried to compile the most simple program as i can:


    Qt Code:
    1. #include "test.h"
    2. #include <qapplication.h>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. test w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    test.h:

    Qt Code:
    1. #ifndef TEST_H
    2. #define TEST_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_test.h"
    6.  
    7. class test : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. test(QWidget *parent = 0, Qt::WFlags flags = 0);
    13. ~test();
    14.  
    15. private:
    16. Ui::testClass ui;
    17. };
    18.  
    19. #endif // TEST_H
    To copy to clipboard, switch view to plain text mode 

    And errors i got:

    Qt Code:
    1. 1>------ Build started: Project: test, Configuration: Release Win32 ------
    2. 1>Build started 2012-09-01 15:19:31.
    3. 1>InitializeBuildStatus:
    4. 1> Touching "Release\test.unsuccessfulbuild".
    5. 1>CustomBuild:
    6. 1> All outputs are up-to-date.
    7. 1>ClCompile:
    8. 1> All outputs are up-to-date.
    9. 1> main.cpp
    10. 1>QtCore.lib(qeventdispatcher_win.obj) : error LNK2019: unresolved external symbol _WSAAsyncSelect@16 referenced in function "public: void __thiscall QEventDispatcherWin32Private::doWsaAsyncSelect(int)" (?doWsaAsyncSelect@QEventDispatcherWin32Private@@QAEXH@Z)
    11. 1>QtGui.lib(qaccessible_win.obj) : error LNK2019: unresolved external symbol __imp__PlaySoundW@12 referenced in function "public: static void __cdecl QAccessible::updateAccessibility(class QObject *,int,enum QAccessible::Event)" (?updateAccessibility@QAccessible@@SAXPAVQObject@@HW4Event@1@@Z)
    12. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmGetDefaultIMEWnd@4 referenced in function "struct HWND__ * __cdecl getDefaultIMEWnd(struct HWND__ *)" (?getDefaultIMEWnd@@YAPAUHWND__@@PAU1@@Z)
    13. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmGetContext@4 referenced in function "struct HIMC__ * __cdecl getContext(struct HWND__ *)" (?getContext@@YAPAUHIMC__@@PAUHWND__@@@Z)
    14. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmReleaseContext@8 referenced in function "void __cdecl releaseContext(struct HWND__ *,struct HIMC__ *)" (?releaseContext@@YAXPAUHWND__@@PAUHIMC__@@@Z)
    15. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmNotifyIME@16 referenced in function "void __cdecl notifyIME(struct HIMC__ *,unsigned long,unsigned long,unsigned long)" (?notifyIME@@YAXPAUHIMC__@@KKK@Z)
    16. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmGetCompositionStringW@16 referenced in function "long __cdecl getCompositionString(struct HIMC__ *,unsigned long,void *,unsigned long)" (?getCompositionString@@YAJPAUHIMC__@@KPAXK@Z)
    17. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmAssociateContext@8 referenced in function "void __cdecl enableIme(class QWidget *,bool)" (?enableIme@@YAXPAVQWidget@@_N@Z)
    18. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmSetCandidateWindow@8 referenced in function "public: virtual void __thiscall QWinInputContext::update(void)" (?update@QWinInputContext@@UAEXXZ)
    19. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmSetCompositionWindow@8 referenced in function "public: virtual void __thiscall QWinInputContext::update(void)" (?update@QWinInputContext@@UAEXXZ)
    20. 1>QtGui.lib(qwininputcontext_win.obj) : error LNK2019: unresolved external symbol _ImmSetCompositionFontW@8 referenced in function "public: virtual void __thiscall QWinInputContext::update(void)" (?update@QWinInputContext@@UAEXXZ)
    21. 1>C:\Users\Daniel\Desktop\test\Win32\Release\\test.exe : fatal error LNK1120: 11 unresolved externals
    22. 1>
    23. 1>Build FAILED.
    24. 1>
    25. 1>Time Elapsed 00:00:02.30
    26. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    To copy to clipboard, switch view to plain text mode 

    No idea what's going on. I use Qt Visual Studio Addin. QtGui.lib and QtCore.lib are included in linker.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    How does your .pro file look? Did you forget to configure for a static build?

  3. #3
    Join Date
    Aug 2012
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    I don't have any *.pro file. Visual Studio 2010 doesn't create any one. I thought about create one, but i have no idea how to attach it to project.

    But my main problem and reason why i need static linking. I have to use QAxWidget in my project, but as far as i know i have to do static build to be able to include ActiveQt to my project. Am i right?

    EDIT

    Hmm ... i think that i found something. Is it true that i can't build project just using Visual Studio, but i have to use qmake and then nmake?
    Last edited by Blood9999; 1st September 2012 at 16:34.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    I build all of my projects using the Qt Add-in for Visual Studio. You don't need to use qmake or nmake - it is all done within VS using the toolbar / menu commands to build projects.

    Use the Qt Add-in to add a new Qt GUI project and select QWidget as the class to use as the base of the GUI. If you've tried to build a new project manually, you have most likely have a project where some required libraries are not being included in the link. Using the Add-in avoids this problem.

    You do not need a static Qt build in order to use ActiveQt. It works just fine in the default DLL version. I don't know where you got that crazy idea. Nothing in Qt requires a static build, and in fact static libraries are incompatible with the LGPL license under which Qt is released.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    Quote Originally Posted by d_stranz View Post
    ...
    and in fact static libraries are incompatible with the LGPL license under which Qt is released.
    No they're not.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6
    Join Date
    Aug 2012
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    You do not need a static Qt build in order to use ActiveQt. It works just fine in the default DLL version. I don't know where you got that crazy idea. Nothing in Qt requires a static build, and in fact static libraries are incompatible with the LGPL license under which Qt is released.
    Then show me where have you got any kind of ActiveX DLL file

  7. #7
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    those PARTICULAR libraries may be static libs, but that does not mean the whole of your Qt build has to be static...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  8. #8
    Join Date
    Aug 2012
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    As far as i know, you can't build your application half static and half shared ;D

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    wow, you still don't get it?

    You can link against static and shared libs. You do not need a static Qt build to use the qt activex sttic libs.

    capisce?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    No they're not.
    LGPL requires that you be able to substitute the functionality contained in a library at run time by substituting another library with the same functionality (and function signatures), unless you provide the source code for the library in question (see clause 4.d). So either you have to make available the source code to the Qt libraries you have statically linked against, or you have to link dynamically.

    You can link against static and shared libs. You do not need a static Qt build to use the qt activex sttic libs.
    I think you would likely run into problems trying to compile the application. You have to declare the compile-time constants (QT_DLL, etc.) that tell the compiler how to bring in the class and methods declarations from the Qt header files. If you are using part of Qt that has been compiled statically and part that has been compiled into DLLs, the function signatures for any dependencies between the libraries are probably going to be inconsistent with one definition or the other. This isn't to say it can't be done, but you probably couldn't do it as a project-level declaration - it would have to be done on a header-by-header basis where you have to modify the QT_DLL define as appropriate for each source and header file (and all their dependencies). I think it would be a real mess.

    Then show me where have you got any kind of ActiveX DLL file
    You know, I think you are right - the vcproj files for QAxContainer.lib and QAxServer.lib build them both as static libraries, not DLLs. (As does the .pro file: CONFIG += qt warn_off staticlib)

    The header files for the ActiveQt classes declare them without qualifiers (e.g. class QAxBase), whereas the headers for the core Qt classes it uses are declared with the export macro (e.g. class Q_CORE_EXPORT QObject), which I guess does the right magic to ensure that the declarations are consistent when link time comes.
    Last edited by d_stranz; 2nd September 2012 at 18:21.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  11. #11
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    LGPL requires that you be able to substitute the functionality contained in a library at run time by substituting another library with the same functionality (and function signatures), unless you provide the source code for the library in question (see clause 4.d). So either you have to make available the source code to the Qt libraries you have statically linked against, or you have to link dynamically.
    Exactly. Static libraries can be used and can comply with LGPL.

    As for the issue of qt/ActiveQt, it is all explained in the docs http://doc.qt.io/qt-4.8/activeqt so there is no static/shared problem here either. Not to mention your edit that says that dll import macros wont get in the way of statically linking against those libs when you need to also link against the rest of your non-static Qt build
    Last edited by amleto; 2nd September 2012 at 18:30.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  12. #12
    Join Date
    Dec 2014
    Posts
    1
    Platforms
    Unix/X11 Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    imm32.lib
    winmm.lib
    Ws2_32.lib
    add these librarys to Project

  13. #13
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [MSVC 2010] Static linking and unresolved external symbols

    I am sure that after almost 2 1/2 years, everyone is excited and happy to finally get this answer.

Similar Threads

  1. Replies: 13
    Last Post: 6th May 2019, 23:02
  2. Replies: 4
    Last Post: 9th May 2016, 12:30
  3. Replies: 2
    Last Post: 11th February 2011, 14:44
  4. Replies: 2
    Last Post: 31st October 2009, 03:41
  5. Replies: 16
    Last Post: 23rd May 2008, 10:12

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.