the make program (and, moreover, cmake ) doesn’t have a relationship as such, as I understand it.
for link_directories is an indication to the builder that runs at compile time.
you want to give instructions to the loader . but the system loader searches for libraries by the names specified in the executable file in those directories in which it (the loader) is configured to search for them at boot time (that is, even before the program runs). You can reconfigure the system bootloader using the ldconfig program (see man ldconfig
).
without reconfiguring the bootloader, you can give such an indication using the environment variable, for example, by running not the program directly, but the script in any programming language you prefer (for example, the shell language) in which to call your program by specifying the path using the environment variable LD_LIBRARY_PATH
(paths) to your library (s) :
LD_LIBRARY_PATH=путь программа
so that the path to the library is "wired" in the executable file
you can dynamically load the library at runtime (specifying a relative or full path to it) using the dlopen()
function.