1

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?

1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.