0

I am working on an embedded Linux target, gcc 9.2. If I link with -rpath=/usr/local/lib, the readelf utility shows me the RPATH entry, as expected. If I link with -rpath=$ORIGIN, readelf shows no RAPTH, and nothing involving ORIGIN. The link command appears to be correct: x86_64-poky-linux-g++ ... -Xlinker -rpath=$ORIGIN .... Any ideas?

Phillip
  • 13
  • 4
  • Can you try to quote `$ORIGIN`? – SethMMorton Apr 13 '22 at 16:35
  • Like this? `x86_64-poky-linux-g++ ... -rpath="$ORIGIN" ...` Didn't change anything, I'm afraid. – Phillip Apr 13 '22 at 16:50
  • Perhaps I should add that I'm cross-compiling in an Eclipse CDT Managed Build project; hence I had to specify `-rpath=$$ORIGIN` in the "C/C++ Build > Settings > Cross G++ Linker > Miscellaneous > Other options" section. I am showing the link command as it appears in the console. – Phillip Apr 13 '22 at 16:55
  • I meant single quotes – SethMMorton Apr 13 '22 at 16:56
  • Hot diggity! `x86_64-poky-linux-g++ ... -Xlinker -rpath='$ORIGIN' ...` did the trick. Could you explain? Does the passage through g++ to the linker do some substitution? – Phillip Apr 13 '22 at 17:00

1 Answers1

0

Simply typing $ORIGN was causing your shell to expand the variable before the value was passed to the linker. Since you likely had no ORIGIN environment variable, you were getting nothing.

You need to prevent shell expansion so that $ORIGIN literally is passed to the linker - to do that, one uses single quotes. Double quotes won't work because variables are interpolated in double quotes.

SethMMorton
  • 45,752
  • 12
  • 65
  • 86