[Interest] To rpath or not when building Qt

Nikos Chantziaras realnc at gmail.com
Wed Mar 11 22:50:52 CET 2015


On 10/03/15 21:07, Scott Aron Bloom wrote:
> When building Qt for distribution via LGPL of a closed source product
> using shared libraries.
>
> What is the best method to make sure the plugins pickup the Qt libraries
> you are shipping?

As Thiago mentioned, you can use RPATH. However, RPATH is overridable. 
What you *really* want to set is RUNPATH. If you want to load the 
plugins from a directory that exists inside the directory of your 
executable, then use "$ORIGIN" as the prefix.

To do that, link with:

   -Wl,-rpath=\$ORIGIN/lib,--enable-new-dtags

This will look in the lib subdirectory first for libraries and only 
consider default locations if a library is not found in lib. So if you 
install your main binary in:

   /opt/myapp/mybinary

Libraries will be searched in:

   /opt/myapp/mybinary/lib

For reference, if you want to use RPATH instead of RUNPATH, use:

   -Wl,-rpath=\$ORIGIN/lib,--disable-new-dtags

Note: it is somewhat of a nightmare to escape the "$" in "\$ORIGIN" in a 
way that can make it undamaged to the final link command. The shell must 
receive "\$ORIGIN", and until it makes it there, it can pass through 
several processing stages. You might need an unholy amount of escape 
sequences ("\\\\$ORIGIN" or similar.) Trial end error :-/




More information about the Interest mailing list