在我的开发Mac中,我将dylib放在/usr/local / lib目录中,并将其拖到项目中.
该应用程序已编译并在我的计算机上运行完美.
要将此应用程序分发到其他Mac,我创建一个文件构建阶段的副本,并说“将该dylib复制到Frameworks目录”.
应用程序构建成功,我确实看到dylib被复制到应用程序包中的Frameworks目录.
问题是当我在另一台没有安装此dylib的常规Mac上运行此应用程序时.我收到一个错误说:
dyld: Library not loaded: /usr/local/lib/mylib.dylib
解决方法
<you_app_path>/Contents/Frameworks
但是您尝试从/usr/local / lib加载它,在部署机器上它不可用.从Apple Framework Programming Guide开始:
To embed a framework in an application,there are several steps you must take:
You must configure the build phases of your application target to put the framework in the correct location.
You must configure the framework target’s installation directory,which tells the framework where it will live.
You must configure the application target so that it references the framework in its installation directory.
现在,你说构建阶段是好的;我还假设您正确发送了应用程序目标构建设置.剩下的是配置框架目标的安装目录.
如果您没有自己构建框架,您应该能够通过更改框架安装路径来修复此问题,以便相对于加载器(您的应用程序)定义它,如下所示:@loader_path /../ Frameworks /(或@executable_path /../框架).你可以通过install_name_tool做到这一点.
如果您自己编译私有框架,则可以在Xcode构建设置中定义其安装位置.