What is the swiftc argument -Xlinker '-rpath=$ORIGIN' for?

When building a swift package from the command line via SPM using the verbose option, I notice the executable I am building is linked with this option:

-Xlinker '-rpath=$ORIGIN'

Why is this required, and what is the value of $ORIGIN` here?

The comment here explains a bit:

$ORIGIN is a magic value used by Linux's runtime linker... this gives a starting point if you want to read more: https://unix.stackexchange.com/questions/22926/where-do-executables-look-for-shared-objects-at-runtime


Thank you this is very informative!

1 Like