How to Compile Qt as Static

Making static Build(standalone application) with Qt

You need to build Qt yourself from source. You will definitely want to maintain two builds of Qt. For debugging, you should use the shared build, as this has reasonable link times. For release, you should use the static build, definitely with link time code generation to keep the executable smaller, and expect the build of a trivial application to take on the order of a minute. This is because the "link" really generates machine code for both Qt and your application, and the code is specific to your application, thus making it generally perform better.

The way you do it without wasting disk space for multiple copies of the source is by using out-of-source Qt builds. So far the static Qt 5.1.1 build is broken, so the below only works for Qt 4, with Visual Studio.

  1. Download the source to, say, C:\Qt\4.8.5.

  2. Create C:\Qt\4.8.5-shared. Open the visual studio console, CD there, and run C:\Qt\4.8.5\configure.exe -shared with whatever other options you may have. Then build it using nmake or jom.

  3. Create C:\Qt\4.8.5-static. Open the visual studio console, CD there, and run C:\Qt\4.8.5\configure.exe -static -ltcg with whatever other options you may have. Then build it using nmake or jom.

You'll need to link the plugins statically to your release build of the application.

Qt Creator makes it easy to use multiple builds of Qt in parallel. I routinely do builds using both Qt 4 and Qt 5, both static and shared, with local fixes to Qt 5 to get the static build to work.

Build Qt (static linking) for Visual Studio 2017 32bits

Looks good. My only remarks would be:
To remove gnuwin32 path as I don't see a reason why would you need it.

And consider making a shadow build to keep Qt sources unpolluted.

set _SHADOW_DIR="C:\build_static"
set _SOURCE_DIR="C:\SrcQt5.9.1"
...
cd %_SHADOW_DIR%
call %_SOURCE_DIR%\configure ...

Qt 5.6 msvc static compile

its work here:

  • install python v2.7

  • start menue -> all programs -> visual studio 2013 -> visual studio tools

  • open Developer Command Prompt for VS2013

  • in command line:

    • set QMAKESPEC=win32-msvc2013

    • set QTDIR=C:\Qt\QT-EVE~1.0\qtbase

    • set PATH=C:\Qt\QT-EVE~1.0\qtbase\bin;%PATH%

    • set PYTHONPATH=%C:\Python27%;C:\Python27\Lib

    • cd C:\Qt\qt-everywhere-opensource-src-5.6.0

    • configure -static -platform win32-msvc2013 -nomake examples -nomake tests

  • c or o

  • nmake



Related Topics



Leave a reply



Submit