Home:ALL Converter>How to make binary distribution of Qt application for Linux

How to make binary distribution of Qt application for Linux

Ask Time:2009-06-01T22:01:25         Author:Michael

Json Formatter

I am developing cross-platform Qt application. It is freeware though not open-source. Therefore I want to distribute it as a compiled binary.

On windows there is no problem, I pack my compiled exe along with MinGW's and Qt's DLLs and everything goes great.

But on Linux there is a problem because the user may have shared libraries in his/her system very different from mine.

Qt deployment guide suggests two methods: static linking and using shared libraries. The first produces huge executable and also require static versions of many libraries which Qt depends on, i.e. I'll have to rebuild all of them from scratches. The second method is based on reconfiguring dynamic linker right before the application startup and seems a bit tricky to me.

Can anyone share his/her experience in distributing Qt applications under Linux? What method should I use? What problems may I confront with? Are there any other methods to get this job done?

Author:Michael,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/934950/how-to-make-binary-distribution-of-qt-application-for-linux
RazZziel :

Shared libraries is the way to go, but you can avoid using LD_LIBRARY_PATH (which involves running the application using a launcher shell script, etc) building your binary with the -rpath compiler flag, pointing to there you store your libraries.\n\nFor example, I store my libraries either next to my binary or in a directory called \"mylib\" next to my binary. To use this on my QMake file, I add this line in the .pro file:\n\nQMAKE_LFLAGS += -Wl,-rpath,\\\\$\\$ORIGIN/lib/:\\\\$\\$ORIGIN/../mylib/\n\n\nAnd I can run my binaries with my local libraries overriding any system library, and with no need for a launcher script.",
2012-11-20T17:34:52
sybreon :

You can also distribute Qt shared libraries on Linux. Then, get your software to load those instead of the system default ones. Shared libraries can be over-ridden using the LD_LIBRARY_PATH environment variable. This is probably the simplest solution for you. You can always change this in a wrapper script for your executable.\n\nAlternatively, just specify the minimum library version that your users need to have installed on the system.",
2009-06-01T14:08:40
Joe Corkery :

When we distribute Qt apps on Linux (or really any apps that use shared libraries) we ship a directory tree which contains the actual executable and associated wrapper script at the top with sub-directories containing the shared libraries and any other necessary resources that you don't want to link in.\n\nThe advantage of doing this is that you can have the wrapper script setup everything you need for running the application without having to worry about having the user set environment variables, install to a specific location, etc. If done correctly, this also allows you to not have to worry about from where you are calling the application because it can always find the resources.\n\nWe actually take this tree structure even further by placing all the executable and shared libraries in platform/architecture sub-directories so that the wrapper script can determine the local architecture and call the appropriate executable for that platform and set the environment variables to find the appropriate shared libraries. We found this setup to be particularly helpful when distributing for multiple different linux versions that share a common file system.\n\nAll this being said, we do still prefer to build statically when possible, Qt apps are no exception. You can definitely build with Qt statically and you shouldn't have to go build a lot of additional dependencies as krbyrd noted in his response.",
2009-06-01T14:42:49
kbyrd :

sybreon's answer is exactly what I have done. You can either always add your libraries to LD_LIBRARY_PATH or you can do something a bit more fancy:\n\nSetup your shipped Qt libraries one per directory. Write a shell script, have it run ldd on the executable and grep for 'not found', for each of those libraries, add the appropriate directory to a list (let's call it $LDD). After you have them all, run the binary with LD_LIBRARY_PATH set to it's previous value plus $LDD.\n\nFinally a comment about \"I'll have to rebuild all of them from scratches\". No, you won't have to. If you have the dev packages for those libraries, you should have .a files, you can statically link against these.",
2009-06-01T14:43:16
Mihai Limbășan :

Not an answer as such (sybreon covered that), but please note that you are not allowed to distribute your binary if it is statically linked against Qt, unless you have bought a commercial license, otherwise your entire binary falls under the GPL (or you're in violation of Qt's license.)\n\nIf you have a commercial license, never mind.\n\nIf you don't have a commercial license, you have two options:\n\n\nLink dynamically against Qt v4.5.0 or newer (the LGPL versions - you may not use the previous versions except in open source apps), or\nOpen your source code.\n",
2009-06-01T14:42:25
pi3 :

The probably easiest way to create a Qt application package on Linux is probably linuxdeployqt. It collects all required files and lets you build an AppImage which runs on most Linux distributions.\n\nMake sure you build the application on the oldest still-supported Ubuntu LTS release so your AppImage can be listed on AppImageHub.",
2018-02-04T11:03:05
Egor Nemtsev :

You can look into QtCreator folder and use it as an example. It has qt.conf and qtcreator.sh files in QtCreator/bin.\n\nlib/qtcreator is the folder with all needed Qt *.so libraries. Relative path is set inside qtcreator.sh, which should be renamed to you-app-name.sh\n\nimports,plugins,qml are inside bin directory. Path to them is set in qt.conf file. This is needed for QML applications deployment.",
2017-02-20T09:41:34
yy