Link with -rpath=/usr/local/lib works, -rapth=$ORIGIN does not

799 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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.