向 XCode 4 添加框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6972904/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:40:20  来源:igfitidea点击:

Adding a framework to XCode 4

objective-cxcodeframeworksbuild-automation

提问by Marek Sebera

of course i did research before posting my question.

当然,我在发布我的问题之前做了研究。

I looked at
How to "add existing frameworks" in Xcode 4?
Adding Framework in Xcode 4
Adding an OpenGL framework in Xcode 4
XCode 4 adding dylib

我查看了
如何在 Xcode 4 中“添加现有框架”?
在 Xcode 4 中添加框架 在 Xcode 4 中
添加 OpenGL 框架
XCode 4 添加 dylib

but whole thing is becoming wrong.

但整件事都变得错误了。

My goal: Add (CorePlot) framework to XCode Mac project(not an iPhone one)

我的目标:将 (CorePlot) 框架添加到 XCode Mac 项目(不是 iPhone项目

My environment: OSX Lion 10.7, SDK Lion, XCode 4.1 (4B110)

我的环境:OSX Lion 10.7、SDK Lion、XCode 4.1 (4B110)

My steps:

我的步骤:

  • Opened XCode, created new project
  • Downloaded CorePlot into my libraries directory (like ~/Applications/LIBS)
  • Opened project preferences, via (+) opened dialog to add framework
  • Add existing framework (+ copy files to dest. group if needed)
  • Selected directory was ~/Applications/LIBS/CorePlot/Binaries/MacOS/CorePlot.framework/
  • DnD CorePlot to Frameworks Group
  • Added CorePlot to Build Phases > Link Binary with Libraries
  • 打开 XCode,创建新项目
  • 将 CorePlot 下载到我的库目录中(如 ~/Applications/LIBS)
  • 打开项目首选项,通过 (+) 打开的对话框添加框架
  • 添加现有框架(如果需要,将文件复制到目标组)
  • 选择的目录是 ~/Applications/LIBS/CorePlot/Binaries/MacOS/CorePlot.framework/
  • DnD CorePlot 到框架组
  • 将 CorePlot 添加到 Build Phases > Link Binary with Libraries

and ran my project

并运行我的项目

what I got is this error message:

我得到的是这个错误信息:

dyld: Library not loaded: @loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/metralight-hjuvuwlhgohrtdeepvcymnsaxomc/Build/Products/Debug/metralight.app/Contents/MacOS/metralight
Reason: image not found

And in fact, when I looked into given directory (app bundle) there was no directory Frameworksand so the linking cannot be successful

事实上,当我查看给定目录(应用程序包)时,没有目录Frameworks,因此链接无法成功

I have searched one more, and found, that I can create Build Ruleand copy files into final binary bundle via some script, but is this only way how to do this?

我又搜索了一个,发现我可以Build Rule通过一些脚本创建文件并将其复制到最终的二进制包中,但这是唯一的方法吗?

Isn't there some option to just turn on/off copying linked frameworks to final bundle?

是否有一些选项可以打开/关闭将链接框架复制到最终包?

Note that CorePlot target '.framework' has Dynamic Library Install Nameset to @loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot, so it is looking in right place in final binary bundle

请注意,CorePlot 目标 '.framework' 已Dynamic Library Install Name设置为@loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot,因此它在最终二进制包中寻找正确的位置

回答by Marek Sebera

After adding framework via "Add existing framework"

通过“添加现有框架”添加框架后

  • Go to Project Settings> Build Phases
  • In right bottom corner click Add buid phase> Copy Files
  • Select Destination> Frameworks
  • Drag&Drop framework to files list
  • 前往Project Settings>Build Phases
  • 在右下角点击Add buid phase>Copy Files
  • 选择目的地>Frameworks
  • 将框架拖放到文件列表

And that's it.

就是这样。

回答by Gobra

Another important detail here - you must have the "Runtime search path" to be defined in the projects, it's empty by default.

这里的另一个重要细节 - 您必须在项目中定义“运行时搜索路径”,默认情况下它是空的。

Something like this:

像这样的东西:

LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks