15

ldconfig has two interesting options:

-f conf
      Use conf instead of /etc/ld.so.conf.
-C cache
      Use cache instead of /etc/ld.so.cache.

I tried copying /etc/ld.so.conf to my own home directory, and edited it to include paths to my local libraries e.g. /home/syockit/local/usr/lib etc. And ran

ldconfig -f /home/syockit/ld.so.conf -C /home/syockit/ld.so.cache

and subsequently, to confirm that the libraries are cached, I ran

ldconfig -f /home/syockit/ld.so.conf -C /home/syockit/ld.so.cache -p | less

and it does include all my libraries on top of also including system libraries.

Now, I want to have the default linker use these two. But in man ld.so, I see no mention of being able to use custom .conf or .cache. So what's the point of the above two options of ldconfig then?

syockit
  • 753
  • 2
  • 6
  • 17

2 Answers2

10

I think the answer to your question is no, although you can accomplish the same thing other ways.

in man ld.so, I see no mention of being able to use custom .conf or .cache

True, but there is mention of $LD_LIBRARY_PATH and and --library-path, the former being more generally useful.

what's the point of the above two options of ldconfig then?

So you can create a cache without overwriting the system one, and without having to use the system confs.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
7

/etc/ld.so.conf is only read by ldconfig (the cache generation program), not by ld.so (the dynamic loader). You can change the location of the configuration file if you want to generate a cache that's different from the system default.

/etc/ld.so.cache is read by ld.so and you can't make it read from a different location. It can be nonetheless useful to pass a different output location to ldconfig. The most common use case is probably chroot environments. You can use ldconfig -r /some/root to run ldconfig on an alternate root, and put the output wherever you want (inside or outside that root). You'll need to either emit the output at /some/root/etc/ld.so.cache or copy it there later. There are other fairly obscure use cases, for example if you want to run ldconfig as an unprivileged user (who cannot write to /etc/ld.so.cache) and then move the file into place later.