[Interest] Loading libraries from root folder

Till Oliver Knoll till.oliver.knoll at gmail.com
Mon Sep 9 13:05:07 CEST 2013



Am 09.09.2013 um 17:42 schrieb Joseph W Joshua <joshua at megvel.me.ke>:

> ...
>> 
>> Please see: 
>> http://qt-project.org/doc/qt-5.0/qtdoc/deployment-x11.html#creating-the-application-package
> Thanks,
> 
> LD_LIBRARY_PATH looks like the best option.

Using the rpath linker option with a /relative/ path like "./lib" (relative to the binary) worked for me. So I don't quite follow the disadvantage 

"The disadvantage of the second approach [rpath] is that the user may not have privileges to install into the predetermined path."

given in the above link.

Note that this is also somewhat similar with how libraries are located on OS X: there you use the "install_name_tool" to set both library identifiers as well as (relative) paths (in binaries/libraries) on where to locate them:

  https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html

Note that the man page even mentions "rpath":

" Install_name_tool changes the dynamic shared library install names and or adds, changes or deletes
the rpaths recorded in a Mach-O binary. For this tool to work when the install names or rpaths are
larger the binary should be built with the ld(1) -headerpad_max_install_names option."

So under the hood the same "rpath" mechanism might be used in the end, just like when passing the corresponding rpath option to the linker.

Or in other words: I think using rpath (with relative paths) is a "legimitate" way of telling the runtime linker where to look for dependencies - even though I remember discussions (on qt interest and elsewhere) about (security) issues and "rpath vs runpath": e.g. placing a malicious shared lib could be much easier if the user decides to install the application in the home directory (and the linker would hence search in e.g. ~/myapps/FooApp/lib/ which most likely is writeable for the current user!).

But if you set the LD_LIBRARY_PATH carelessly probably the same security concerns would arise, no?

Anyway, this is probably a good starting point if you want to dwelve further into the whole rpath vs runpath vs ld_library_path vs where_should_i_install_all_my_custom_libs_on_linux discussion:

http://blog.tremily.us/posts/rpath/

(And it probably also sais somewhere that using relative paths with rpath is evil: IIRC the point against it was that it might not work on every possible Linux distro, especially on mobile platforms. But it worked for me so far (on desktops) ;))

Cheers,
  Oliver

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130909/6208a6a0/attachment.html>


More information about the Interest mailing list