Search code examples
shared-librarieslddynamic-libraryld-preload

LD_PRELOAD multiple interdependent libraries


I Have Libraries with a tree of dependencies, i.e. some of the dependencies have other dependencies I want to Preload. How can I do this?

LD_PRELOAD \
/opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libicudata.so.60 \
/opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libicuuc.so.60 \
/opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libicui18n.so.60 \
/opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libQt5Core.so.5 \
MyApp

The LD_PRELOAD call contains is sorted, such that the dependencies are listed before the depending library.

The Linker throws the following error:

ERROR: ld.so: object '/opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libQt5Core.so.5' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

Can the libraries be preloaded to fulfil the dependencies in the correct order?


Solution

  • This error:

    ld.so: object '/opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libQt5Core.so.5' \
    from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
    

    means that the dynamic loader tried to open the library and failed.

    There are several possible reasons for this failure:

    1. The file doesn't exist (use ls -L /opt/yocto/2.5.1/sysroots/core2-64-poky-linux/usr/lib/libQt5Core.so.5 to confirm that it does
    2. The file is for the wrong architecture (e.g. 32-bit ELF when MyApp is 64-bit, or vice versa). Use file MyApp and file libQt5Core.so.5 to confirm that they match.
    3. Something else. Perhaps MyApp was linked with newlib or uClibc, but libQt5Core.so.5 was built with GLIBC (or vice versa).