简体   繁体   English

向XCode 4添加框架

[英]Adding a framework to XCode 4

of course i did research before posting my question. 当然我在发布问题之前做过研究。

I looked at 我在看
How to "add existing frameworks" in Xcode 4? 如何在Xcode 4中“添加现有框架”?
Adding Framework in Xcode 4 在Xcode 4中添加框架
Adding an OpenGL framework in Xcode 4 在Xcode 4中添加OpenGL框架
XCode 4 adding dylib 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 打开XCode,创建了新项目
  • Downloaded CorePlot into my libraries directory (like ~/Applications/LIBS) 将CorePlot下载到我的库目录中(如〜/ 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/ 所选目录是〜/ Applications / LIBS / CorePlot / Binaries / MacOS / CorePlot.framework /
  • DnD CorePlot to Frameworks Group DnD CorePlot到框架组
  • Added CorePlot to Build Phases > Link Binary with Libraries 添加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 Frameworks and so the linking cannot be successful 事实上,当我查看给定目录(应用程序包)时,没有目录Frameworks ,因此链接无法成功

I have searched one more, and found, that I can create Build Rule and 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 Name set 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 ,因此它在最终二进制包中查找正确的位置

After adding framework via "Add existing framework" 通过“添加现有框架”添加框架后

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

And that's it. 就是这样。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM