I have a local shared library which is not in $LD_LIBRARY_PATH. I want to run my executable, but since it cannot find the shared library in the system folders, it outputs "error while loading shared libraries".
A possible fix for this is to export a new LD_LIBRARY_PATH containing the local library folder.
How can I export automatically this environment variable within CMake?
Best How To :
If your shared lib is not build in the same CMake project of your executable, you can use the CMake rpath handling like this:
When you will run
make install, CMake will automatically set the runtime path of your executable to your shared library.
If your shared library is built in the same CMake project, use this:
In this case you must add yourself the directory where your shared library will be installed to the runtime path.
For more information, you can read CMake rpath handling