Are symlinks resolved before or after the dynamic loader figures out the value for the $ORIGIN in the rpath from an executable?

Longer explanation:

I'd like to know if there's an standards-compliant certain behaviour about this, or if it varies across different UNICES (I'm mostly interested in Linux, BSDs, and MacOS):

Let's suppose I build (and install) an executable called myexe with installation prefix set to /my/path/to/local/installations and with $ORIGIN/../lib in its rpath

Now let's suppose I create a symlink like this:

ln -s /my/path/to/local/installations/bin /my/path/to/bin

and then I set /my/path/to/bin in the $PATH environment variable.

When I execute myexe from an arbitrary directory, will $ORIGIN be understood as /my/path/to/bin or as /my/path/to/local/installations/bin?

Or wording the question in another way, will it load dynamic libraries from /my/path/to/lib or from /my/path/to/local/installations/lib?

  • 2
    $ORIGIN will be replaced in linux/glibc with the resolved path, not with the path of the symlink. And $ORIGIN, $LIB or $PLATFORM are not portable and not supported on all Unix systems. – Uncle Billy Jan 16 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.