19

I have found by coincidence that on my Debian Jessie there is no LD_LIBRARY_PATH variable (to be exact printenv | grep LD shows nothing related to linker and echo "$LD_LIBRARY_PATH" shows also nothing).

This is the case in x terminal emulator (which might clear it due to setgid) as well as in basic terminal (Ctrl+Alt+F1).

I know that LD_LIBRARY_PATH may be considered bad so Debian may block it somehow, but on the other hand there are a few files in /etc/ld.so.conf.d/ that contains some directories to be added to LD_LIBRARY_PATH. None of my rc files (that I know of) mess with LD_LIBRARY_PATH either.

Why I don't see an LD_LIBRARY_PATH variable?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
calavera.info
  • 531
  • 1
  • 4
  • 13

1 Answers1

24

Yes, it is normal that you don't have any explicit LD_LIBRARY_PATH. Read also ldconfig(8) and ld-linux(8) and about the rpath. Notice that ldconfig updates /etc/ld.so.cache, not the LD_LIBRARY_PATH. Sometimes you'll set the rpath of an executable explicitly with -Wl,-rpath,directory passed to gcc at link time.

If you need a LD_LIBRARY_PATH (but you probably should not), set it yourself (e.g. in ~/.bashrc).

If you need system wide settings, you could e.g. consider adding /usr/local/lib/ in /etc/ld.so.conf and run ldconfig after installation of every library there.

AFAIK $LD_LIBRARY_PATH is used only by the dynamic linker ld-linux.so (and by dlopen(3) which uses it) after execve(2). See also ldd(1).

Read Drepper's How To Write Shared Libraries for more.

Basile Starynkevitch
  • 10,411
  • 1
  • 32
  • 52
  • That was my mistake, I though that LD_LIBRARY_PATH is the _product_ of running `ldconfig`. Meanwhile it is the _input_ of ldconfig alongside with files in `/etc/ld.so.conf`. – calavera.info Sep 26 '17 at 11:13
  • 1
    My feeling is that `ldconfig` don't use `$LD_LIBRARY_PATH` (which is only used at `ld-linux.so` time) – Basile Starynkevitch Sep 26 '17 at 11:15
  • 3
    @calavera.info it's neither. The dynamic linker uses `LD_LIBRARY_PATH` *together* with the output of `ldconfig` at runtime. `ldconfig` neither uses nor changes `LD_LIBRARY_PATH`. – hobbs Sep 26 '17 at 19:37
  • Now I can see that I had it totally messed up, probably by spending too much time in Java, where "classpath" is virtualy the only configuration of dynamic linking. Everything seems to be clear now, thanks a lot. – calavera.info Sep 27 '17 at 08:41