Linux (or GNU/Linux) in general is considered a major operating system that dominates the cloud/server market. Since Linux is not a single operating system (Linux is offered by different vendors in the form of different Linux distributions that are not entirely compatible) like Windows or macOS, it is very hard for developers to build their applications and expect them to run flawlessly on different Linux distributions (distros). However, if you develop your Linux application on Qt, there is a high chance that it will work on most distributions, if not on all of the major distros out there, as long as the Qt library exists on the target system.
The default kit selection on Linux is much simpler than Windows. Since a 64-bit application has been mainstream and standard on most Linux distros for some time now, we only need to include the GCC 64-bit compiler when installing Qt. There is also an option for Android, but we will talk more about it later:
![](Images/39cbb752-788b-4f19-be8e-80a6fe79aecb.png)
If you are compiling your Linux application on Qt Creator for the first time, I'm pretty sure you will get the following error:
![](Images/8cb011d6-5884-41c7-9359-949a3da431c1.png)
This is because you have not installed the relevant tools required to build Linux applications, such as Make, GCC, and other programs.
Different Linux distros have a slightly different method to install programs, but I won't be explaining every single one of them here. In my case, I'm using an Ubuntu distro, so I did was first opened up the terminal and typed the following command to install the build-essential package which includes Make and GCC:
sudo apt-get install build-essential
The preceding command only works on distros that inherit from Debian and Ubuntu, and it may not work on other distributions such as Fedora, Gentoo, Slackware, and so on. You should search for the appropriate command used by your Linux distro to install these packages, as shown in the following screenshot:
![](Images/ca215015-a2a1-4372-bc16-b295382402fb.png)
Once you have installed the appropriate packages, restart Qt Creator and go to Tools | Options. Then, go to the Build & Run category and open up the Kits tab. You should now be able to select the compilers for both C and C++ options for your Desktop kit:
![](Images/d8efa23d-958b-49c4-a0af-9d9ab6ef91b5.png)
However, you might get another error that says cannot find -lGL when trying to compile again:
![](Images/3fa99b4a-7ff3-4fbb-a194-4fadbb2b8cc1.png)
This is because Qt is trying to look for the OpenGL libraries, and it can't find them on your system. This can be easily fixed by installing the Mesa development library package with the following command:
sudo apt-get install libgl1-mesa-dev
Again, the preceding command only works on Debian and Ubuntu variants. Please look for the appropriate command for your Linux distro if you're not running one of the Debian or Ubuntu forks:
![](Images/469afd43-8058-490f-87dd-f89d97955bd7.png)
Once the package has been installed, you should be able to compile and run your Qt application without any problem:
![](Images/f90b95a8-a587-4cfd-8c60-c291a40177ae.png)
As for using one of the other compilers that are less popular, such as Linux ICC, Nim, or QCC, you must set it manually by clicking on the Add button located on the right-hand side of the Kits interface, then key in all the appropriate settings to get it to work. Most people do not use these compilers, so we'll just skip them for now.
When it comes to distributing Linux applications, it's a lot more complicated than Windows or macOS. This is owing to the fact that Linux is not a single operating system, but rather a bunch of different distros with their own dependencies and configurations, which makes distributing programs very difficult.
The safest way is to compile your program statically, which has its own pros and cons. Your program will become really huge in size, and that makes updating software a great burden to users who have slow internet connections. Other than that, the Qt license also forbids you from building statically if you're not doing an open source project and do not have a Qt commercial license. To learn more about Qt's licensing options, please visit the following link: https://www1.qt.io/licensing-compariso.n.
Another method is to ask your users to install the right version of Qt before running your application, but that will yield a ton of problems on the user side since not every user is very tech savvy and has the patience to go through all those hassles to avoid the dependency hell.
Therefore, the best way is to distribute the Qt library alongside your application, just like we did on the Windows platform. The library might not work on some of the Linux distros (rarely the case, but there is a slight possibility), but that can be easily overcome by creating a different installer for different distros, and everyone's happy now.
However, due to security reasons, a Linux application doesn't usually look for its dependencies in its local directory by default. You must use the $ORIGIN keyword in the executable's rpath setting in your qmake project (.pro) file:
unix:!mac{ QMAKE_LFLAGS += -Wl,--rpath=$$ORIGIN QMAKE_RPATH= }
Setting the QMAKE_RPATH clears the default rpath setting for the Qt libraries. This allows for bundling the Qt libraries with the application. If you want the rpath to include the path to the Qt libraries, don't set QMAKE_RPATH.
After that, just copy all the library files from the Qt installation folder to your application's folder and remove its minor version numbers from the filename. For example, rename libQtCore.so.5.8.1 to libQtCore.so.5 and now it should be able to get detected by your Linux application.
As for application icons, you can't apply any icon to Linux applications by default as it is not supported. Even though some desktop environments such as KDE and GNOME do support application icons, the icon has to be installed and configured manually, which is not very convenient to the users. It may not even work on some user's PC since every distro works a little bit differently than the others. The best way to set icons for your application is to create a desktop shortcut (symlink) during installation and apply the icon to the shortcut.