Platform plugin libraries on GNU/Linux
I am having some problems deploying plugin libraries on GNU/Linux.
For example the platform library libqxcb.so:
libQt5Gui.so.5 => /usr/lib/qt5/lib/libQt5Gui.so.5 (0x00007f1dfc515000)
libQt5Core.so.5 => /usr/lib/qt5/lib/libQt5Core.so.5 (0x00007f1dfbde3000)
This file is hard wired to load the libraries from /usr/lib/qt5/...
After some research I found a possible solution but I am not sure if this is the right way to do it (or if it would even work for plugin libraries):
// modify the relative path
// so the file can load from current or relative path ?
QMAKE_LFLAGS += -Wl,-rpath,"'$$ORIGIN'"
What is the preferred way to handle this?
This blog post is your friend: http://www.tripleboot.org/?p=138 It describes in great detail a few different ways you can achieve this.
I would personally recommend the RPATH method.
Yeah, I had looked at that posting already. This is where the -rpath, $ORIGIN idea came from. I have also looked at articles created for deploying Qt projects on GNU/Linux but they seemed to stop short at the parts I need.
My first attempt was using a shell script and modifying the LD_LIBRARY_PATH which works fine for the application but doesn't extend to the plugins.
I am looking at the RPATH option. There is no issue with the application finding the plugins but that the plugins try to load libraries from the fixed path. This is handled by the Qt application when it loads and not by the operating system. The article mentions that RPATH is ignored in this case.
I am investigating this and will post a solution if I find one. I am looking for a solution that doesn't involve putting libraries outside the folder of the application. I don't want to do a static build if there is another way.
I found a solution to this problem.
For all the plugin libraries you need to set a relative search path. I found a utility "PatchElf":http://nixos.org/patchelf.html that did the trick.
So, in my case, I created a folder for the QtLibraries (qtlibs) and set the relative path like this:
// one dir up and into qtlibs
patchelf --set-rpath ../qtlibs libqxcb.so
The actual executable program can stay with a shell script or can adjusted the same way as the libraries (probably will do it this way) but I don't see an alternative for the plugins (aside from installing in an expected location).
This seems to be a similar to how macdeployqt works on OS X.
I thought this was the answer but it is not.
I find that using rpath the program will only run when I am in the current directory of the program itself. If I navigate to $HOME it won't work because it is looking for everything relative to $HOME.
Maybe a combination of shell scripts and rpath (?). Any suggestions are welcome.
Edit: A combination of a shell script (with 'cd <app folder>') and modifying rpath works. I don't like it though, it seems over the top. Probably will just stick to distributing the source code.