find_library so and all symlinks

How to find a library (find_library) and all associated symlinks to that library? E.g. a library typically looks like

libfoo.so
libfoo.so.1
libfoo.so.1.0.0 

where the latter two are symlinks. Is there a better way than stating a find_library 3 times?

When you found the .so, you can resolve the symlink to get the .so.1.0.0 and then read the name that ld will use from the ELF headers.

At least that will be more consistent than 3 find_library calls

Not sure I understand how do that with cmake. Typically it would look like this;

libfoo.so -> libfoo.so.1.0.0*
libfoo.so.1 -> libfoo.so.1.0.0*
libfoo.so.1.0.0*

Finding libfoo.so is easy. Some libraries are installed with one symlink, other with two symlinks. Also I want to install the symlink and not a copy of the symlink.

What exactly do you want to achieve? Maybe there’s a simpler way…

Probably not as efficient as what you’re looking for, but find -L $dirname -maxdepth 1 -samefile $libname.so should at least get the same answer.

I have a target baz that links against library foo in the toolchain sysroot. Now I want to install the foo library to CMAKE_INSTALL_PREFIX.

You can use file(GET_RUNTIME_DEPENDENCIES) for that.

1 Like