What path does @loader_path resolve to?

19,486

Your guess is right: in this case @loader_path is the path to the directory, containing zlib.so. But there probably will be problems with using this lib. Where did you get that lib? If you are building it by yourself, see this question for some info.
The @loader_path is useful for the frameworks and plugins, but not for the standalone libraries.

Share:
19,486

Related videos on Youtube

ChrisB
Author by

ChrisB

Updated on May 30, 2020

Comments

  • ChrisB
    ChrisB almost 4 years

    I'm having a hard time understanding the absolute path that a @loader_path within a file refers to.

    user@local:~$ otool -L zlib.so 
    zlib.so:
        @loader_path/../../libz.1.dylib (compatibility version 1.0.0, current version 1.2.7)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
    

    I want to know where the system looks to find libz.1.dylib.

    From some Mac documentation:

    @loader_path/ This variable is replaced with the path to the directory containing the mach-o binary which contains the load command using @loader_path. Thus, in every binary, @loader_path resolves to a different path

    I would have guessed this means that @loader_path is just the path to the object file (zlib.so), but that doesn't seem to be true.

    Is there any command line utility that will resolve @loader_path to the actual path that is used when attempting to open a library?

  • ChrisB
    ChrisB almost 11 years
    Thanks for the confirmation on @loader_path. Ultimately, I want the complete list of libraries that a given object file depends upon, and where the system is going to look for them. Is there a simple way to generate that list?
  • cody
    cody almost 11 years
    Well, object file doesn't depend on any library. Linker sets dependencies, so only target binary has dependencies. And otool -L <binary> is the way to see them. And all additional info which can help to resolve those paths is in man dyld (that is the link you've provided)
  • P.R.
    P.R. over 9 years
    May I ask why this is not useful for standalone libraries? I am trying to get a library compiled to be portable. Should I use something else? I got here by looking up what @loader_path means from blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
  • cody
    cody over 9 years
    As far as I remember because @loader_path is about relative stuff. In plug-ins you have few binaries, which can be relative to each other, and if you will link them using @loader_path, you can move plug-in itself around the file system safely. But in case of standalone library why do you need that path? Take a look at section about @loader_path in man dyld for info
  • clearlight
    clearlight over 5 years
    @cody Thanks for the higher level answer that goes with the question, as well as the hint that man dyld documents it!!
  • technerd
    technerd over 5 years
    Good read to get basic understanding of @executable_path , @loader_path and @rpath wincent.com/wiki/…