This article is reproduced from: https://wincent.com/wiki/@executable_path,[email protected][email protected]. Personally feel that writing is very good, concise and clear.
Absolute paths
Useful for frameworks installed in shared locations. Example:
- Install Path:
/Library/Frameworks/Foo.framework/Versions/A/Foo
@executable_path
Useful for frameworks embedded inside applications, because it allows your to specify the location of the framework Relativ E to the application ' s executable:
- Install Path:
@executable_path/../Frameworks/Foo.framework/Versions/A/Foo
- Application Location:
/Applications/Foo.app
- Executable Path:
/Applications/Foo.app/Contents/MacOS
- Framework Location:
/Applications/Foo.app/Contents/Frameworks/Foo.framework
- Linker puts all this together to figure out the framework binary can is found at:
/Applications/Foo.app/Contents/MacOS/../Frameworks/Foo.framework/Versions/A/Foo
@loader_path
Available From mac OS x 10.4 tiger onwards; useful for frameworks embedded inside Plug-ins, Because it allows specify the location of the framework relative to the plug-in ' s code (remember, Plug-ins Actually know where they is going to being installed, relative to the application, so knowing @executable_path  DOESN ' t help us in this case):
- Install path:
@loader_path/.. /frameworks/foo.framework/versions/a/foo
- application location:
/applications/foo.app
- plug-in location:
/library/application support/foo/plug-ins/bar.bundle
- executable path:
/applications/foo.app/contents/macos
- Loader path:
/library/application Support/foo/plug-ins/bar.bundle/contents/macos
- Framework location:
/library/application support/foo/plug-ins/bar.bundle/contents/frameworks/ Foo.framework
- Linker puts all this together to figure out the the framework binary can is found At:
/library/application support/foo/plug-ins/bar.bundle/contents/macos/. /frameworks/foo.framework/versions/a/foo
Note that if the ' loader ' is an application rather than a plug-in, the @loader_path
ends up being equivalent to @executable_path
.
@rpath
New in Mac OS X 10.5 Leopard is @rpath
. Key points:
@rpath
Instructs the dynamic linker to search a list of paths in order to locate the framework
- Critically, this list was embedded in the loading application
- This means. A single framework
@rpath/Foo.framework/Versions/A/Foo
with can being made to work in a number of different ways; Ely no longer limited by the choice of specifying your "install path" using either @executable_path
or@loader_path
- The down side:you now has to pass additional linker flags when building the host application (eg.
-rpath @executable_path/../Frameworks
or /Library/Frameworks
; note th At specifying both would cause the dynamic linker to try looking in both locations)
Sources
- Nice overview:http://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html
- Docs for using Pfiddlesoft frameworks (I-ve never used these, but the manual itself makes some nice general points about u Sing frameworks): Http://pfiddlesoft.com/frameworks/downloads/Assistive_Application_Programming_Guide.pdf
@executable_path in Mac OSX, understanding of @load_path and @rpath