Let's say I build myTest with cmake. myTest uses /opt/path1/lib/lib.so at compile and link time. After running it a few times I decide that I want myTest to now use /opt/path2/lib.so (same lib name, same interfaces, just different path).
This might be cause I want to temporarily test changes to lib.so without affecting others that might be using it. I also may not have the source to myTest but know that it uses lib.so.
If I used a Makefile and used regular gnu/g++ make I can make this happen by setting LD_LIBRARY_PATH in the local folder. CMake ignores LD_LIB_PATH - so how do I make this happen?
For find a library at runtime, ldd uses (among other things) RPATH directories, embedded into the executable.
By default, when build the executable/library, CMake adds to RPATH directories, where linked libraries are located.
E.g., when link with library
/opt/path1/lib/lib.so, CMake adds directory/opt/path1/libto RPATH. Solddalways findslib.solibrary as/opt/path1/lib/lib.so.For tell CMake to not set RPATH, set CMAKE_SKIP_RPATH variable:
After that,
lddwill searchlib.soin directory, listed inLD_LIBRARY_PATHenvironment variable.