[Interest] Correcting deployment linkages in Linux shared libraries

Thiago Macieira thiago.macieira at intel.com
Wed Dec 4 05:58:41 CET 2013


On terça-feira, 3 de dezembro de 2013 19:51:44, Bob Hood wrote:
> There's probably an obvious solution to this, so forgive me if so.
> 
> I'm building an Qt-based application that uses shared libraries as plug-ins.
> Both the application and the plug-ins link to the Qt libraries in my
> installation (in this case, in /usr/local/qt/4.8.4/...).  When I deploy, I
> copy the Qt shared libraries to which the system linked into the same
> folder as the application and plug-ins (making sure to retain the symbolic
> links).  I also include a qt.conf file in the same folder so the
> application will pick up the Qt shared libraries that it finds in the
> folder with it.

qt.conf does not affect shared library loading. And the Linux library loader 
does not care for same-path libraries either. It respects only 
/etc/ld.so.conf, LD_LIBRARY_PATH environment variable and the DT_RUNPATH 
header.

> However, the plug-in shared libraries don't seem to be adhering to this
> redirection mechanism.  If I deploy to a "clean" installation of my Linux
> distribution, the shared libraries have changed their linkages to the Qt
> version found in /usr/lib64 (which, in this case, is 4.6.2) instead of using
> those in the folder with them.  I discovered using the ldd tool.
> 
> Is there a post-build action I need to perform to "fix" these linkages, like
> the "install_name_tool" utility under OS X?  If not, how do I get these
> plug-ins to use the Qt deployed with them?

Post-build? No.

Add an -rpath $ORIGIN to each and every executable, library and plugin so that 
the shareed libraries are found in the same directory. That's a linker 
argument, so you pass this to the compiler:

	-Wl,-rpath,$ORIGIN

Since $ is a shell special, you need to escape it:

	'-Wl,-rpath,$ORIGIN'

If you're using qmake, you add that to the QMAKE_LFLAGS variable, but you need 
to add a couple more levels of escaping:

	QMAKE_LFLAGS += \'-Wl,-rpath,\$\$ORIGIN\'

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131203/c6282563/attachment.sig>


More information about the Interest mailing list