Mac OSX中的@executable_path, @load_path和@rpath的理解(网摘)

Mac OSX中的@executable_path, @load_path和@rpath的理解

原文出处:【24K纯开源

Note: this article is actually about the @executable_path@load_path and @rpath install paths used by the linker on Mac OS X; wiki titles can't include underscores, however, because they are ambiguous with spaces.

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 you to specify the location of the framework relative 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 that the framework binary can be 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 you to specify the location of the framework relative to the plug-in's code (remember, plug-ins may not actually know where they are going to be 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 that the framework binary can be 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 is embedded in the loading application
  • this means that a single framework with @rpath/Foo.framework/Versions/A/Foo can be made to work in a number of different ways; that is, you are effectively no longer limited by the choice of specifying your "install path" using either@executable_path or @loader_path
  • the down side: you now have to pass additional linker flags when building the host application (eg. -rpath @executable_path/../Frameworks or /Library/Frameworks; note that specifying both will cause the dynamic linker to try looking in both locations)

Sources

 

转载于:https://www.cnblogs.com/sz-leez/p/4864444.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值