OSX:更改.framework的路径 [英] OSX: changing path of .framework
问题描述
我的Mac OS应用程序与非系统提供的框架Foo.framework链接.我在XCode中添加了对该框架的引用,并且该应用程序构建良好.我也有一条将框架复制到输出Frameworks文件夹(MyApp.app/Contents/Frameworks)的规则.但是,在运行时,二进制文件正在〜/Library/Frameworks中寻找框架,并且该应用程序无法加载.
My Mac OS application links with a non-system-provided framework Foo.framework. I added a reference to the framework in XCode and the app builds fine. I also have a rule which copies the framework into the output Frameworks folder (MyApp.app/Contents/Frameworks). However, at runtime the binary is looking for the framework in ~/Library/Frameworks and the app fails to load.
otool -l MyApp.app也告诉我,它正在/Users//Library/Frameworks中寻找框架.
otool -l MyApp.app also tells me that it's looking for the framework in /Users//Library/Frameworks.
有人可以解释为什么会这样吗,以及使应用程序在应用程序包的Frameworks文件夹中显示的正确方法是什么?
Can someone explain why this happens, and what the right way to make the app look in the application bundle's Frameworks folder is?
我棘手的解决方法是包括一个自定义脚本,以使用install_name_tool更改mach-o二进制文件中的路径,但是我敢肯定有一种干净的方法可以做到这一点.
My hacky workaround is to include a custom script to change the path in the mach-o binary using install_name_tool, but I'm sure there is a clean way of doing this.
推荐答案
您在正确的轨道上.
之所以会这样,是因为在OS X上,创建库时会将"install_name"
记录在库中.然后将该install_name复制到与其链接的任何应用程序.
It happens because on OS X an "install_name"
is recorded in the library when it's created. That install_name is then copied to any application which links with it.
解决问题的最佳"方法是修改框架的来源,以便在构建框架时设置-install_name
链接器标志.
The "best" way to solve the problem is to modify the source of the framework so that the -install_name
linkder flag is set when the framework is built.
但是,这通常是不可能的,要么是因为您没有源,要么是框架中有大量的autoconf东西,这使它几乎不可能实现.在这种情况下,请使用带有-id标志的install_name_tool来更改库中记录的install_name
.
However, that's often not possible, either because you don't have the source, or the framework has a huge mess of autoconf stuff that makes it near impossible. In that case, use install_name_tool with the -id flag to change the recorded install_name
in the library.
那么,话虽如此,您将其更改为什么?
So, with all that said, what do you change it to?
@executable_path/../Frameworks/Foo.framework/Foo(或其他名称)
@executable_path/../Frameworks/Foo.framework/Foo (or whatever the name is)
因此,从包含Foo.framework的目录中:
So, from the directory containing Foo.framework:
install_name_tool -id @executable_path/../Frameworks/Foo.framework/Foo Foo.framework/Foo
在运行时,加载程序会将@executable_path解析为应用程序可执行文件的路径.显然,您还需要设置一个复制文件"构建阶段,以将框架复制到应用程序包的Framework文件夹中.
At runtime, the loader will resolve @executable_path to the path to the application's executable. Obviously you also need to setup a Copy Files build phase to copy the framework into the Framework folder of the application bundle.
您还可以将install_name_tool
与-change标志一起使用,以在将库链接到应用程序后更改其安装名称,但这显然不是最佳选择.链接之前先对其进行修复.
You can also use install_name_tool
with the -change flag to change the install_name of a library after it's already been linked into the application, but that's obviously suboptimal. Fix it before linking.
这篇关于OSX:更改.framework的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!