5

I want to use a static build of Qt 5.4. Since there is no precompiled static build available, you have to build one from the Qt source code yourself.

My environment is the following:

  • Windows 7 x64
  • Visual Studio 2013 Ultimate Update 4
  • Qt5 Visual Studio Add-in 1.2.4
  • ActivePerl / ActivePython installed (required to build Qt source)

My procedure was the following (cf. Qt Documentation > Qt 5.4 > Qt for Windows - Building from Source):

  • Download qt-everywhere-opensource-src-5.4.0.zip
  • Extract to a temp folder
  • Open a command prompt as described here (basically, this is similar to open a "Visual Studio Command Prompt" and adding some paths to the path variable)
  • Run configure with the following command

    configure -c++11 -mp -release -static -nomake tests -nomake examples -prefix D:\Qt\qt-5.4.0-x86-msvc2013-compact-static -platform win32-msvc2013 -opengl desktop -no-icu -skip webkit
    
  • Run nmake and nmake install

All this run through without errors.

Then in Visual Studio, I changed the Qt version of an existing Qt project to D:\Qt\qt-5.4.0-x86-msvc2013-compact-static as this was the output folder of the above procedure.

However, now I get tons of unresolved symbol errors of the following kind (build configuration "release"):

error LNK2001: unresolved external symbol "__imp__glBindTexture@8". Qt5Gui.lib(qopenglfunctions.obj)
...
error LNK2001: unresolved external symbol "_hb_blob_create".    Qt5Gui.lib(qharfbuzzng.obj)
...
error LNK2001: unresolved external symbol "_hb_face_create_for_tables". Qt5Gui.lib(qharfbuzzng.obj)
....
error LNK2001: unresolved external symbol "_WSAAsyncSelect@16". Qt5Core.lib(qeventdispatcher_win.obj)

A shared library / dynamic linking build with similar options (-platform win32-msvc2013 -opengl desktop -no-icu -skip webkit) works just fine.

What am I doing wrong?


Update Jan 6th:

1) As already mentioned in the comments, this may be a bug in Qt, so I created a bug report (QTBUG-43636), and later I found a probably related bug (QTBUG-38913). (Sorry, I can post no more than 2 links)

2) I found out (thanks to karlphillip) that you can reduce the number of error messages if you add some libraries to your additional dependencies in Visual Studio

  • Ws2_32.lib resolves one error message (out of 103)
  • opengl32.lib resolves 47 error messages

This means there are now "only" 55 error messages left. Maybe there are still more libraries missing?

4
  • 1) Smells like a bug in Qt. Have you considered reporting it? 2) Not being a Windows prouser myself: are you sure that now it's 100% supported to provide a prefix path / to run make install?
    – peppe
    Jan 3, 2015 at 21:39
  • Have you seen this? Jan 3, 2015 at 21:44
  • It's written on the website that you can use prefix and nmake install doc.qt.io/qt-5/windows-building.html Adding imm32.lib winmm.lib Ws2_32.lib does not resolve the issue.
    – manuel
    Jan 3, 2015 at 22:01
  • Update: To be more precise, adding Ws2_32.lib actually resolves one of the 103 errors. ("_WSAAsyncSelect@16" in qeventdispatcher_win.obj) The other 102 are still present when I add those three libs. Update 2: Now there is also a bug report.
    – manuel
    Jan 5, 2015 at 13:51

1 Answer 1

11

I found the solution:

You have to add the following libraries to your additional dependencies in Visual Studio:

Ws2_32.lib opengl32.lib qtharfbuzzng.lib

Then, my project finally compiled.

However, that is not the end of the story:

Although successfully compiled, my application showed the following error message on startup:

This application failed to start because it could not find or load the Qt platform plugin "windows".

To solve this, you have to add even more libraries to your additional dependencies:

imm32.lib winmm.lib Qt5PlatformSupport.lib qwindows.lib

...and the following to your additional library directories:

$(QTDIR)\plugins\platforms

...and the following to your source code:

#include <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

Done! Finally, I was able to link against static Qt libraries.

It was worth the effort:

The cold startup time of my application improved dramatically from about 10 seconds to less than 1 second. And instead of 14 MB DLL-files I only have to deploy a single 8 MB EXE-file.

3
  • Great tutorial, thanks. I only add that when creating static libraries a change have to be made within ${QtDir}\mkspecs\win32-msvc2013\qmake.conf. Details here.
    – Pavel
    Feb 5, 2015 at 11:57
  • @mr.pohl: Yes, if you want to link against static Visual Studio runtime libraries, you have to make these changes. But that's not mandatory, since you can just ask the end user to install the appropriate Visual C++ Redistributable Package. (see here). Also, it must be mentioned that Qt advises not to link against static Visual Studio runtime. (see here)
    – manuel
    Feb 6, 2015 at 13:44
  • 1
    Thx,but where can find those dependencies?
    – xiaohuo
    May 27, 2016 at 8:05

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.