'Setting linker preferences for multiple shared libraries of same name

I link my application against multiple shared libraries, one of which is Google's gRPC, which in turn links against boringSSL. I also link against other libraries, which in turn link against OpenSSL. In the end, calling ldd on my binary and grepping for ssl gives:

    libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f62f35c8000)
    libssl.so => /usr/local/grpc/lib/libssl.so (0x00007f62f28b6000)

I would rather not statically link against gRPC and friends. Is there a way I can set preferences that the second result should be used for gRPC only and the first for everything else?

I am using CMake as a build project, if that helps.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source