这是由以下原因引起的运行时错误 Dynamic Linker
dyld: Library not loaded: @rpath/...
...
Reason: image not found
错误Library not loaded
与@rpath
表示Dynamic Linker
找不到二进制文件。
检查动态框架是否已添加到 General -> Embedded Binaries
检查@rpath
使用者(应用程序)和生产者(动态框架)之间的设置:
- 动态框架:
Build Settings -> Dynamic Library Install Name
- 应用:
Build Settings -> Runpath Search Paths
Build Phases -> Embed Frameworks -> Destination, Subpath
动态链接器
Dynamic Library Install Name(LD_DYLIB_INSTALL_NAME)
播放时loadable bundle
(Dynamic framework
作为派生对象)使用它-二进制文件(不是.framework)的路径。是的,他们具有相同的名称,但是是用二进制文件和资源内。
这个路径目录可以是绝对的或相对的(例如,,)。相对路径更可取,因为它会与锚一起更改,当您将分发包作为单个目录分发时,锚会很有用dyld
Dynamic Library Install Name
MyFramework.framework
packaged bundle
MyFramework
@executable_path
@loader_path
@rpath
绝对路径 - 框架1例
//Framework1 Dynamic Library Install Name
/some_path/Framework1.framework/subfolder1
@executable_path
@executable_path -相对于条目二进制- Framework2例如
用例:嵌入Dynamic framework
到应用程序
//Application bundle(`.app` package) absolute path
/some_path/Application.аpp
//Application binary absolute path
/some_path/Application.аpp/subfolder1
//Framework2 binary absolute path
/some_path/Application.аpp/Frameworks/Framework2.framework/subfolder1
//Framework2 @executable_path == Application binary absolute path
/some_path/Application.аpp/subfolder1
//Framework2 Dynamic Library Install Name
@executable_path/../Frameworks/Framework2.framework/subfolder1
//Framework2 binary resolved absolute path by dyld
/some_path/Application.аpp/subfolder1/../Frameworks/Framework2.framework/subfolder1
/some_path/Application.аpp/Frameworks/Framework2.framework/subfolder1
@loader_path
@loader_path -相对于捆绑这是该二进制的所有者
使用的情况下:与嵌入框架的框架- Framework3_1与Framework3_2内
//Framework3_1 binary absolute path
/some_path/Application.аpp/Frameworks/Framework3_1.framework/subfolder1
//Framework3_2 binary absolute path
/some_path/Application.аpp/Frameworks/Framework3_1.framework/Frameworks/Framework3_2.framework/subfolder1
//Framework3_1 @executable_path == Application binary absolute path
/some_path/Application.аpp/subfolder1
//Framework3_1 @loader_path == Framework3_1 @executable_path
/some_path/Application.аpp/subfolder1
//Framework3_2 @executable_path == Application binary absolute path
/some_path/Application.аpp/subfolder1
//Framework3_2 @loader_path == Framework3_1 binary absolute path
/some_path/Application.аpp/Frameworks/Framework3_1.framework/subfolder1
//Framework3_2 Dynamic Library Install Name
@loader_path/../Frameworks/Framework3_2.framework/subfolder1
//Framework3_2 binary resolved absolute path by dyld
/some_path/Application.аpp/Frameworks/Framework3_1.framework/subfolder1/../Frameworks/Framework3_2.framework/subfolder1
/some_path/Application.аpp/Frameworks/Framework3_1.framework/Frameworks/Framework3_2.framework/subfolder1
@rpath-运行路径搜索路径
Framework2示例
以前,我们必须设置一个与dyld一起使用的框架。这不方便,因为同一框架不能与其他配置一起使用
@rpath
是一个复合概念,它依赖于外部(应用程序)和嵌套(动态框架)部分:
//Application Runpath Search Paths
@executable_path/../Frameworks
//Framework2 Dynamic Library Install Name
@rpath/Framework2.framework/subfolder1
//Framework2 binary resolved absolute path by dyld
//Framework2 @rpath is replaced by each element of Application Runpath Search Paths
@executable_path/../Frameworks/Framework2.framework/subfolder1
/some_path/Application.аpp/Frameworks/Framework2.framework/subfolder1
* ../
-转到当前目录的父目录
otool
-目标文件显示工具
//-L print shared libraries used
//Application otool -L
@rpath/Framework2.framework/subfolder1/Framework2
//Framework2 otool -L
@rpath/Framework2.framework/subfolder1/Framework2
//-l print the load commands
//Application otool -l
LC_LOAD_DYLIB
@rpath/Framework2.framework/subfolder1/Framework2
LC_RPATH
@executable_path/../Frameworks
//Framework2 otool -l
LC_ID_DYLIB
@rpath/Framework2.framework/subfolder1/Framework2
install_name_tool
使用以下命令更改动态共享库的安装名称 -rpath
CocoaPods
使用use_frameworks!
[关于]来规范Dynamic Linker
[词汇]
Link Binary with Libraries
并且Xcode知道以某种方式将它们复制到您的应用程序包中,而对于自定义框架,这根本不会发生。