How to make binary distribution of Qt application for Linux

后端 未结 8 924
小蘑菇
小蘑菇 2020-12-13 20:36

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

相关标签:
8条回答
  • 2020-12-13 21:13

    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.

    Make sure you build the application on the oldest still-supported Ubuntu LTS release so your AppImage can be listed on AppImageHub.

    0 讨论(0)
  • 2020-12-13 21:18

    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.

    For 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:

    QMAKE_LFLAGS += -Wl,-rpath,\\$\$ORIGIN/lib/:\\$\$ORIGIN/../mylib/
    

    And I can run my binaries with my local libraries overriding any system library, and with no need for a launcher script.

    0 讨论(0)
  • 2020-12-13 21:18

    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.

    The 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.

    We 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.

    All 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.

    0 讨论(0)
  • 2020-12-13 21:18

    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:

    Setup 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.

    Finally 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.

    0 讨论(0)
  • 2020-12-13 21:24

    This article has information on the topic. I will try it myself: http://labs.trolltech.com/blogs/2009/06/02/deploying-a-browser-on-gnulinux/

    In a few words:

    • Configure Qt with -platform linux-lsb-g++
    • Linking should be done with –lsb-use-default-linker
    • Package everything and deploy (will need a few tweaks here but I haven't yet tried it sorry)
    0 讨论(0)
  • 2020-12-13 21:33

    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.

    Alternatively, just specify the minimum library version that your users need to have installed on the system.

    0 讨论(0)
提交回复
热议问题