0

I am trying to find from my binary (which is supposed to be able to run on any distro), the canonical path to system libraries for a given distro / architecture.

Precisely, I am trying to load VST plug-ins which are shared objects which all distros store in folders such as /usr/lib/vst/xxx.so, /usr/lib32/vst/xxx.so, /usr/lib64/vst/xxx.so, etc.

Some distros just have /usr/lib, some have /usr/lib and /usr/lib64 be different folders with a different content entirely, some have /usr/lib symlinked to /usr/lib64... so I cannot just add all of them to my search path as that would sometimes give duplicates.

What tools can I use outside of a filesystem search which would be too slow, from a C++ program, to get the path to the folder that interests me, no matter which distro, past present or future, my users are running ?

Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75
  • _so I cannot just add all of them to my search path as that would sometimes give duplicates_ You _can_ add them all if you do `stat` on them and keep a copy of the `struct`. Skip if return is -1 (dir does not exist). Otherwise, compare `st_dev` and `st_ino` against all the previous entries. If they both match the candidate is a dup--skip it (i.e. it is a symlink/hardlink to one of the previous entries). – Craig Estey Apr 19 '22 at 17:39
  • After that you may want to scan the directory looking for a `.so` (via `readdir`). Process the [ELF] header and reject the directory if the lib is the _wrong_ arch (e.g. 32 vs 64 bit or aarch64 vs x86_64, etc). – Craig Estey Apr 19 '22 at 17:56

0 Answers0