Xcode:将全新框架链接到全新应用程序失败并显示“找不到图像”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14924513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode: Linking brand new framework to brand new app fails with "image not found"
提问by Myrne Stol
I'm totally new to Xcode and Objective-C, but an experienced (web) programmer otherwise. I want to create an app that includes a self-made framework.
我对 Xcode 和 Objective-C 完全陌生,但在其他方面我是一位经验丰富的(网络)程序员。我想创建一个包含自制框架的应用程序。
Now I've read quite a bit on it, I think I've got a reasonable grasp of how OS X resolves dependencies at runtime, and the role of @rpath, @executable_path and @loader_path.
现在我已经阅读了很多关于它的内容,我想我已经合理地掌握了 OS X 如何在运行时解决依赖关系,以及 @rpath、@executable_path 和 @loader_path 的作用。
I did the following to create the framework:
我做了以下事情来创建框架:
- Create new Cocoa Framework named Test.
- Set installation directory to "@rpath".
- Add "Test.h" to public headers.
- Click run.
- Right click on Test.framework under "Products", choose Show in Finder. It's a directory called "Test.framework" in the "Debug" directory of the project. It seems to have reasonable contents (Versions/A directory and symlinks to "Headers", "Resources" and the "Test" binary)
- 创建名为 Test 的新 Cocoa 框架。
- 将安装目录设置为“@rpath”。
- 将“Test.h”添加到公共标题。
- 点击运行。
- 右键单击“产品”下的 Test.framework,选择在 Finder 中显示。它是项目“Debug”目录下的“Test.framework”目录。它似乎有合理的内容(Versions/A 目录和指向“Headers”、“Resources”和“Test”二进制文件的符号链接)
I did the following to create the app:
我执行以下操作来创建应用程序:
- Create new Cocoa app named "TestApp".
- Add test framework to project. Choose "Add files to project". Select "Test.framework" directory from "Release" directory of the Test framework project. "Copy items into destination group's folder" is checked Leave "Create groups for any added folders." on.
- Make sure framework files are copied to application bundle. Choose "Add Build Phase" -> "Add Copy Files" Drag Test.framework folder (or group?) from the sidebar into the Copy Files area.
- Add an extra "framework search path" named "@executable_path/../Frameworks"
- 创建名为“TestApp”的新 Cocoa 应用程序。
- 将测试框架添加到项目中。选择“将文件添加到项目”。从Test框架项目的“Release”目录中选择“Test.framework”目录。选中“将项目复制到目标组的文件夹中”保留“为任何添加的文件夹创建组”。在。
- 确保将框架文件复制到应用程序包中。选择“添加构建阶段”->“添加复制文件”将 Test.framework 文件夹(或组?)从侧边栏拖到复制文件区域。
- 添加名为“@executable_path/../Frameworks”的额外“框架搜索路径”
When I choose run, I get the following warning during build:
当我选择运行时,我在构建过程中收到以下警告:
Build target TestApp
Ld /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp normal x86_64 cd /Users/meryn/Work/test-app/TestApp setenv MACOSX_DEPLOYMENT_TARGET 10.8 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug -F/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug -F/Users/meryn/Work/test-app/TestApp "-F@executable_path/../Frameworks" -filelist /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Intermediates/TestApp.build/Debug/TestApp.build/Objects-normal/x86_64/TestApp.LinkFileList -mmacosx-version-min=10.8 -fobjc-arc -fobjc-link-runtime -framework Cocoa -framework Test -o /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp
ld: warning: directory not found for option '-F@executable_path/../Frameworks'
构建目标 TestApp
Ld /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp normal x86_64 cd /Users/meryn/Work/test-app/TestApp setenv GETLOYMENT_TAR 10.8 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10 .8.sdk -L/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug -F/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqrmapyfz/TestApp-ajwvknoonliuqqrmapyfz /Debug -F/Users/meryn/Work/test-app/TestApp "-F@executable_path/../Frameworks"-filelist /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Intermediates/TestApp.build/Debug/TestApp.build/Objects-normal/x86_64/TestApp.LinkFileList -mmacosx-version-min=10.8 -fobjc-arc -fobjc-link-runtime -framework Cocoa -framework Test -o /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp
ld:警告:找不到选项“-F@executable_path/../Frameworks”的目录
I can imagine this warning is to be expected, as Ld may not know about "@executable_path" at all. Is this correct?
我可以想象这个警告是意料之中的,因为 Ld 可能根本不知道“@executable_path”。这样对吗?
Subsequently, running the app fails with:
随后,运行该应用程序失败:
dyld: Library not loaded: @rpath/Test.framework/Versions/A/Test Referenced from: /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp Reason: image not found
dyld:库未加载:@rpath/Test.framework/Versions/A/Test 引用自:/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/ MacOS/TestApp 原因:找不到图像
The peculiar thing is that the TestApp.app package does contain a Frameworks directory, with the Test.framework directory inside. Given what I understand about how OS X would search for dependencies, I think the search path that I added should resolve fine.
奇怪的是,TestApp.app 包确实包含一个 Frameworks 目录,其中包含 Test.framework 目录。鉴于我对 OS X 如何搜索依赖项的了解,我认为我添加的搜索路径应该可以正常解析。
This is on XCode 4.6, OS X 10.8.
这是在 XCode 4.6,OS X 10.8 上。
otool -L TestApp
gives
otool -L TestApp
给
TestApp:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
@rpath/Test.framework/Versions/A/Test (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.33.0)
测试应用程序:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa(兼容版本1.0.0,当前版本19.0.0)
@rpath/Test.framework/Versions/A/Test(兼容版本 1.0.0,当前版本 1.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation(兼容版本300.0.0,当前版本945.11.0)
/usr/lib/libobjc.A.dylib(兼容版本 1.0.0,当前版本 228.0.0)
/usr/lib/libSystem.B.dylib(兼容版本 1.0.0,当前版本 169.3.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit(兼容版本 45.0.0,当前版本 1187.33.0)
Is it ok to see "@rpath" unexpanded here?
在这里可以看到未展开的“@rpath”吗?
What am I doing wrong?
我究竟做错了什么?
回答by bdash
Since the library identifier is set to an @rpath
-prefixed path, the application linking to the library needs to specify one or more -rpath
options indicating what dyld
should substitute the @rpath
variable with when searching for the library at runtime. A typical value would be @loader_path/../Frameworks
if you're copying your framework in to TestApp.app/Contents/Frameworks
. You can set the value of the -rpath
arguments using the LD_RUNPATH_SEARCH_PATHS
('Runpath Search Paths') configuration setting in Xcode on your TestApp target.
由于库标识符设置为带@rpath
前缀的路径,链接到库的应用程序需要指定一个或多个-rpath
选项,指示在运行时搜索库时dyld
应该用什么替代@rpath
变量。一个典型的值是,@loader_path/../Frameworks
如果您将框架复制到TestApp.app/Contents/Frameworks
. 您可以-rpath
使用LD_RUNPATH_SEARCH_PATHS
TestApp 目标上 Xcode 中的('Runpath Search Paths') 配置设置来设置参数的值。
I can imagine this warning is to be expected, as Ld may not know about "@executable_path" at all. Is this correct?
我可以想象这个警告是意料之中的,因为 Ld 可能根本不知道“@executable_path”。这样对吗?
It's not useful to add @executable_path/../Frameworks
to Xcode's framework search paths. The framework search paths are a build-time concept of the static linker (ld
), while the @executable_path
variables are a runtime concept of the dynamic linker (dyld
).
添加@executable_path/../Frameworks
到 Xcode 的框架搜索路径是没有用的。框架搜索路径是静态链接器 ( ld
)的构建时概念,而@executable_path
变量是动态链接器 ( dyld
)的运行时概念。