TransWikia.com

How to determine the default shared library path?

Unix & Linux Asked by Wang on October 31, 2021

Some of distro is /lib64 some of them is /lib/x86_64-linux-gnu, there maybe other format. Is there a uniform way to determine this in bash?

2 Answers

First you should figure out the goal to specify the path. It can be one of:

  1. Where to search already installed libraries.
  2. Where to install your libraries, to make them visible to linkers or runtime loaders.
  3. Where to install your libraries, to conform to distro policy.

For (3), the only real source is distro policy description that is a human readable document. You can't determine this from /etc/ld.so.conf, ldconfig cache, etc., because you can't find out what location is preferred and what one is legacy; some hint on this can be got by counting libraries but this is definitely not work for shell script.

For (1) and (2), read and interpret /etc/ld.so.conf (but this isn't trivial because it usually includes references to other files or wildcards of directory contents). You may also parse output of ldconfig -p and accumulate listed directories. But beware of possible conflicts with existing libraries and of need to remake ldconfig cache after changing library set.

Answered by Netch on October 31, 2021

Usually you can get this information by reading /etc/ld.so.conf. That file may include other files; on my system, it includes all files in /etc/ld.so.conf.d.

Note that there are multiple directories that will be searched. Note also that this does not affect the path of the dynamic linker, ld.so, which is embedded in the binary and is usually uniform for a given architecture and ABI.

Answered by bk2204 on October 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP