How to release a Qt/C++ application on Linux and Windows?
Asked Answered
K

3

6

I developped an application in C++ using Qt for the graphic interface and now I would like to release it for linux and for Windows. I've been looking through documentation, forums and tutorials but I can't really understand what need to be done...

I'm pretty confused between the different terms used : what is the difference between releasing and deploying ? when do you need an installer and if needed, how to create one ?

What are the different steps to create the .exe of Windows ? and its equivalent for the different versions of Linux (Debian, Ubuntu, Ubuntu Mate)?

I am currently on Ubuntu and used Qt Creator to code the application.

As far as I know, I need to deploy Shared Libraries.

Any help, answer, guide or documentation for beginner would be of great help and very welcome :)

Kennie answered 23/4, 2018 at 13:29 Comment(0)
A
8

There are several ways to deploy your application

1. Deploy your application with windeployqt/linuxdeployqt

This is the easiest way, windeployqt or linuxdeployqt is an application that will copy all required dependencies to your executable folder. Ready to run on another computer.

The steps are simple:

  1. Compile your binary in release mode
  2. Open the Qt developer console and type windeployqt "C:\folder\of\your\executable" (linuxdeployqt will be very similar)
  3. All libraries required to run the application on another computer are copied to to your application folder. You can create an archive and send it to someone else.

Note: linuxdeployqt is third-party.

2. Static build

Static build will be a single binary at the end that includes all Qt code. You can ship your single binary to someone, no additional libraries are required to run it. The executable is larger since all the Qt code is linked inside your executable.

The steps are as following:

  1. Download the Qt source code
  2. Unzip it to a folder
  3. Open the developer console of your installed compiler (i. e. MingW or MSVC)
  4. Switch to the folder and type

    ./configure -static -static-runtime

  5. When the configuration is done type nmake or make to build Qt statically.
  6. When the build process has finished create a new kit in Qt Creator and select the new qmake.exe or qmake from your source-code folder.
  7. Select in the project settings your kit to build a statically executable that requires not additional libraries.

3. Offline/Online Installer

This step requires some reading and fine tuning. Qt comes with an IFW (Installer Framework) where you can create online and offline installers. The installer will contain a .7z file of your executable and all dependencies. The installer is more comfortable for the user. It can create shortcuts, check available disk space, etc.

IIRC you need build the installer statically for MSVC or you have to ship the runtime libraries. If build with MingW you probably will not need any runtime libraries.

It is up to you which method you choose. If you own the commerical license you can ship all your closed source as static builds, but in general it's better to ship it as a dynamic build especially if you use OpenSSL where users can quickly exchange vulnerable libraries themself if required.

Artis answered 23/4, 2018 at 19:53 Comment(7)
Thank you for your answer :) Currently I'm doing the deployment through Linux, but I'll keep your answer in mind for when I deploy through windows :)Kennie
Juliette Marquis: Linux will be completely the same. You use linuxdeployqt. Static builds, installers are basically the same. So the answer is for both.Artis
Juliette Marquis: I just added linuxdeployqt to my post. On linux you select qmake instead of qmake.exe. Anything else is the same. You can ship single binaries on linux by compiling it statically for example.Artis
Juliette Marquis: on linux you can additionally create a software package i. e. .deb file that installs everything, but the answer is already covered here by the other post. Now you have 4 ways to deploy your application.Artis
Thank you very much for your edit and your answers ! :D I still wonder, is your 1st method possible for deploying for Windows from Linux ?Kennie
Juliette Marquis: no, you need to compie on the target OS (Windows) .If you want to build for all OS from Linux for example, you need to learn about cross compiliing. This is a much bigger task and sometimes not easy to set-up.Artis
There is no ./configure dir or file or such in my QT project. Is that normal?Cavity
I
0

As far as I know, I need to deploy Shared Libraries.

Probably not. First, notice that you don't release for Linux (in general), but for a particular Linux distribution. Details matter and are different on Ubuntu 15, Ubuntu 16, Debian 9, Fedora ... etc.

(I guess it could be the same on Windows: the version of Windows could matter, so Windows 7 not the same as Windows 10)

You should prefer to use the installed Qt on the target Linux distribution (its minor version would be different from one distro to another).

You probably want to make a software package, for the package manager of your target Linux distribution. On Debian or Ubuntu, that would be some .deb package.

(you can't be sure that your .deb for Ubuntu would work for Debian, but that is usually the case)

A package manager handles dependencies. So if your user would install a correct .deb provided by you, the package manager would either fail or (more often) download and install all the required dependencies (e.g. Qt).

(Or you could distribute the source code - perhaps as free software -, and leave the task of compiling it to your users or to distribution makers)

How to make a Linux package is well documented by the particular distribution you are targetting, and is a different question. For Debian see here.

Improbable answered 23/4, 2018 at 13:51 Comment(6)
Thank you for your reply :) "You should prefer to use the installed Qt on the target Linux distribution (its minor version would be different from one distro to another)." : this would require any user to install Qt on its computer right ? The thing is, I might give it to people who don't know how to code... Another thing is that I need to make a release for at least 4 different Linux distribution...Kennie
No. If you make a correct juliette.deb the command used to install that would care of dependencies and will download the Qt binary packages if they are missingImprobable
So, the only thing I would need is a .deb ? It would take care of everything ?Kennie
BTW, you need to improve your question, instead of giving details in comments hereImprobable
Yes, "It would take care of everything ", spend a few hours reading about package managementImprobable
"Another thing is that I need to make a release for at least 4 different Linux distribution...". You can just create deb and rpm packages and list it's dependencies in there. This will cover most of the distros and install all dependencies automagically.Norris
M
0

Another approach is:

  1. Open your project in Qt.

  2. Select projects from left.

  3. In Buils Steps select Add Build Step

  4. Complete the form as below:

    Command: C:\Qt\Qt5.12.12\5.12.12\mingw73_64\bin\windeployqt.exe

    Argument: C:\path\to\your\project\release\folder\yourapp.exe

Example: consider the projet name is TestApp and its address is C:\TestApp. The argument should be like:

C:\build-TestApp-Desktop_Qt_5_12_12_MinGW_64_bit-release\release\TestApp.exe

Wrking Directory: %{buildDir}

Doing this way, every time that you build your project, related libraries would be copied to your release folder.

Mammiemammiferous answered 13/10 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.