Correctly link libraries with specific soname on linux

My project uses other libraries on linux x86_64. The other libraries are available as precompiled library files. Meaning I have a folder with 34 .so files. Most of these have full version numbers. For example: `libgentl.so.1.0.0`.

The issue I have is that when I build my application, I get linker errors as:

`warning: libgentl.so.1, needed by libarena.so.1, not found (try using -rpath or -rpath-link)`

This tells me that libarena.so.1 has a reference to libgentl.so.1 built-in and the linker looks for it, but I don’t have that file. Normally this is fixed by putting a symbolic link from libgentl.so.1 to libgentle.so.1.0.0. However, my repository is cross platform, so I often use it on windows as well and I cannot keep the symbolic links.

Hence, I generate them using the cmake `file(CREATE_LINK ${target_path} ${link_path} SYMBOLIC)` command during generation. That seems to work as I can see the symbolic links. But clearly, my linker cannot. So, I am searching for the correct way to handle this.

My project setup is as follows: I have an externals folder in which I put all the precompiled libraries of the other library. That project does not have cmake support, so I have to do everything manually. Thus, for each “lib**.so.v.v.v” I create a target with:

add_library(${imported_lib_name} SHARED IMPORTED)
set_target_properties(${imported_lib_name} PROPERTIES
            IMPORTED_LOCATION "${library_path_release}"
            IMPORTED_LOCATION_DEBUG "${library_path_debug}"
            IMPORTED_CONFIGURATIONS "Release;Debug")

where ${library_path_…} is the full absolute path and file name to the lib (e.g. libgentle.so.1.0.0)

Then, I create all the symlinks. I just create them, I don’t create targets for them. Perhaps I need to do that as well??

Finally, I create a target to hold them all together:

add_library(supplierSDK INTERFACE)
target_include_directories(supplierSDK INTERFACE ${library_path_include_dir})
target_link_libraries(supplierSDK INTERFACE ${imported_lib_name}) # times 34
target_link_directories(supplierSDK INTERFACE ${library_path_lib_dir})

The last line I don’t know I need, it is an attempt to fix the linker error, but it seems not to work.

So, can anybody help me understand what the correct way to handle this is? Given the .so.v.v.v lib file, is there a way to make CMake handle this such that the linker can find it even if it links to .so or .so.v ?? Or is there a manual way to get the symlinks detectable by the linker?

Also, as a bonus question: once I have this building, I will also need to update my install target, so any pointers if I need to do anything special there are also much appreciated.

PS: I am building this on WSL, but I don’t think this is relevant.

I wanted to share that adding this line:

set(CMAKE_BUILD_RPATH "${root}/lin64/lib")

seems to help the linker find the necessary libraries (put this before any add_library call). I just don’t know if this is a hacky or a good way to do this.
It still have to make all the symbolic links manually.

and I assume that for the install I will need to use CMAKE_INSTALL_RPATH ?