views:

1391

answers:

5

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 destributing 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?

Thanks.

+5  A: 

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.

sybreon
+1  A: 

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

If you have a commercial license, never mind.

If you don't have a commercial license, you have two options:

  1. Link dynamically against Qt v4.5.0 or newer (the LGPL versions - you may not use the previous versions except in open source apps), or

  2. open your source.

Mihai Limbășan
+2  A: 

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.

Joe Corkery
+2  A: 

I can't up-vote or comment yet, but 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 want. If you have the dev packages for those libraries, you should have .a files, you can statically link against these.

kbyrd
A: 

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)

Yorgos Pagles