Do I absolutely need the new 2.18 dynamic linker to run a program with glibc-2.18?
Yes (well, almost. See footnote).
This would avoid me having to set up and continuously update the paths of the 2.18 dynamic linker.
A common technique is to create a g++
shell wrapper, e.g. g++glibc2.18
, and encapsulate adding the necessary link arguments there. Then a simple make CXX=g++glibc2.18
would do the right thing.
Can't the standard linker do it?
No. See this answer for explanation.
If I compile with the 2.18 dynamic linker but without --rpath, the program doesn't work. Why?
See the same answer.
Should I be using -L/path/to/glibc-2.18/lib in the compilation command (in addition to --rpath and --dynamic-linker)?
Yes, if you want to use symbols that are present in glibc-2.18 but not present in your system library. Otherwise, no.
Footnote:
As an alternative, you could build your program without the special flags, then use "explicit loader invocation" to actually run it: /path/to/glibc-2.18/lib/ld-2.18.so /path/to/a.out
.
Beware: this doesn't always work: if the program likes to re-exec
itself (and under other rare conditions). You may also have trouble debugging it when it is invoked that way.