Making static Build(standalone application) with Qt

15,460

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.

Share:
15,460
harveyslash
Author by

harveyslash

Lost soul swimming in a fish bowl

Updated on June 04, 2022

Comments

  • harveyslash
    harveyslash almost 2 years

    I started out with Qt a while back. I have downloaded the windows 32bit version(666mB),and nothing else. I have made a simple calculator app. The app runs when I run it from Qt creator, but the built exe shows dlls missing. I don't want to use dependency walker.I want to create a static build(I read about it , but I am not able to get it running)

    My objective is to make a fully functional calculator (no installer), without having to manually add the dependencies. I have read about the configure -static, but I didn't understand how to use it. Thanks in advance for the help.

  • JBentley
    JBentley over 10 years
    Can you clarify in what way the static Qt 5.1.1 build is broken? Do you know if it is fixed in 5.2? I'd also be interested to know what local fixes you did to get the static build to work. +1 for the answer.
  • Kuba hasn't forgotten Monica
    Kuba hasn't forgotten Monica over 9 years
    @JBentley See this answer.