https://stackoverflow.com/questions/13334300/how-to-build-and-install-gcc-with-built-in-rpath is a bit dated, but might be helpful. It says in part:  Using --with-boot-ldflags="-Wl,-rpath,/some/path" on the configure step seems to work for me on gcc 4.8.3. The docs discuss this a bit https://gcc.gnu.org/install/configure.html - Dan On Thu, May 28, 2020 at 7:55 PM Patrick Herbst via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > > I have the base gcc that came with my distro and i'd like to have the > option of using a newer version without replacing the older one. > > I'd like to install the newer version in a different path, like /opt. > > I run into a problem though when compiling with the newer version in > /opt, it links against the libstdc++ in /opt, but at runtime the > executable tries to link with the systems version in /usr/lib. > > Is there a way to have the gcc in /opt automatically set the rpath > when linking so that executables can run against the /opt libstdc++? >