Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making static Build(standalone application) with Qt [duplicate]

Tags:

c++

static

qt

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.

like image 872
harveyslash Avatar asked Sep 22 '13 06:09

harveyslash


1 Answers

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.

like image 134
Kuba hasn't forgotten Monica Avatar answered Nov 09 '22 19:11

Kuba hasn't forgotten Monica