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:
swift-package-manager/BuildPlan.swift at cb52a5a6ae0f9397abfef8150e9c00486db46f45 · apple/swift-package-manager · GitHub

$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

3 Likes

Thank you this is very informative!

1 Like