Setting LD_LIBRARY_PATH to custom .so file used by gcc only works partially
Trying to compile with various gccs that use libmpfr.so.4 on Ubuntu Bionic fails as a lot of people know. The message is: "cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory". The most common solution suggested seems to be a symlink from libmpfr.so.6 to the above. As I was crosscompiling on arm I struggled instead to solve this within CMake. That is, I tried to get the compiler to use the .so file provided to me in a bundle along with the compiler and other tools by the end user of the library I'm building.
Here is the CMake part of the issue: if I append the LD_LIBRARY_PATH with the custom location of this .so file the compiler check in the toolchain file happily works (which it does not if I don't set this PATH, then it fails on the error above). However, when building libraries in the main CMakeLists it fails again on the same error: "cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory" This surprises me as I can verify that the global LD_LIBRARY_PATH is the same as in the working toolchain file example.
Is this a bug or have I missed something?