I have a non-system install of g++ and am trying to compile a program using
/MYINSTALLDIR/g++ -L/MYINSTALLLIBDIR -Wl,-rpath,MYINSTALLLIBDIR main.cpp -o tester
but when I then run
ldd ./tester
I get that the libstdc++ and other linked gcc/g++ libraries are the system installs and not the those in the specified rpath location.
I've read through linking g++ 4.8 to libstdc++, and the only other option I see to try is changing the g++ spec file. Since it is owned by root this would be problematic for me.
Any suggestions?
(Note, I've checked that LD_LIBRARY_PATH="" too. I would prefer not to change LD_LIBRARY_PATH.)
EDIT: I tried looking at the NEEDED and RPATH fields in the binary and they are what I would expect. For example, NEEDED includes "libstdc++" and RPATH is simply the value of MYINSTALLLIBDIR.
I then set LD_DEBUG="libs" and re-ran ldd on tester. It looks like ldd is seeing the correct library path before the system version, but not choosing it. The output related to libstdc++ is below:
13337: find library=libstdc++.so.6 [0]; searching
13337: search path=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls/x86_64:/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls:/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/x86_64:/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2 (RPATH from file ./tester)
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls/x86_64/libstdc++.so.6
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls/libstdc++.so.6
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/x86_64/libstdc++.so.6
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/libstdc++.so.6
13336: 13337: find library=libc.so.6 search cache= [/etc/ld.so.cache0]; searching
13336: search cache=/etc/ld.so.cache
13337: trying file=/usr/lib64/libstdc++.so.6
13336: 13337: trying file=
I believe the correct libstdc++ should be "libstdc++.so" in the /opt/rh/.../4.8.2 folder. There is no "libstdc++.so.6" there.
EDIT: Marc Glisse is correct. It turns out the new gcc libstdc++.so just selects the previously installed system version. So this appears to be the correct behavior.