TL;DR Why is it better to place a symlink to a shared library at /etc/lib(64)/
or why is it better to create a *.conf file in /etc/ld.so.conf.d/
.conf file
Assuming i have my custom binary at /opt/foo/
, shipping with it's own shared libraries. The common way (known to me) is to place a file at /etc/ld.so.conf.d/foo.conf
like follows:
# Link foo libraries. This file is included in /etc/ld.so.conf
/opt/foo/lib
/opt/foo/otherlibs
and run ldconfig
afterwards.
symlinks
But I found out that I can also link my libraries into /usr/lib
(or lib64) like this:
for f in /etc/foo/{lib,otherlibs}/*; do
ln -s $f /usr/lib64/$(basename $f)
done
and I won't have to run ldconfig
afterwards.
What are the pros/cons of these two ways?
I can imagine that the "symlink"-way isn't very nice to handle when uprading the application or the library versions. In general, the ".conf"-way seems more modular and more Linux-ish to me.
I occasionally came across this because we have to encrypt (and only decrypt at runtime) a specific library. ldconfig
doesn't recognize the library when encrypted (still in ELF format) so the only suitable way to me was to place a link to the specific *.so file in /usr/lib64
/usr
, okay. But what is the difference in how the OS scans available libraries? I refer to the behavior that .so's in/usr/lib
are found be default, whilst new versions of .so's referred by/etc/ls.so.conf.d
are only found after I ranldconfig
– void Feb 17 '22 at 07:36ld.so
looks for libraries in/lib
and/usr/lib
as a last resort, so it will find new libraries there even if they aren’t inld.so.cache
. Seeman ld.so
and What is the default value of LD_LIBRARY_PATH? for details. – Stephen Kitt Feb 17 '22 at 12:39