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?
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
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.
First you should figure out the goal to specify the path. It can be one of:
- Where to search already installed libraries.
- Where to install your libraries, to make them visible to linkers or runtime loaders.
- 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
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.