处理iOS Framework项目的依赖项 [英] handling dependencies for iOS Framework project

查看:922
本文介绍了处理iOS Framework项目的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此方法创建了iOS Framework项目: https://github.com/jverkoey/iOS -Framework

I've created iOS Framework project using this method: https://github.com/jverkoey/iOS-Framework

工作非常简洁,但我对如何包含我的框架工作所需的库/框架感到困惑,特别是,如何做到这一点,以防万一使用我的框架的第三方客户端应用程序也可以包含这些库而不会发生冲突。

Works pretty neat but I'm a little confused on how to include libraries/frameworks that are needed by my framework to work and, in particular, how to do it so that in case 3rd party client app that uses my framework can include these libs as well without conflicts.

假设我的框架代码需要这两件事:

Let's say my framework code needs these two things:


  • FacebookSDK.framework

  • libFlurry.a

第一个是iOS框架。当我将它添加到我的框架中的Link Binary With Libraries阶段并尝试编译使用我的框架的客户端项目时,链接器会抱怨缺少符号 - 我需要将FacebookSDK添加到客户端项目中很好:如果客户端应用程序想要使用Facebook,则不存在冲突的可能性。

The first one is an iOS Framework. When I add it to "Link Binary With Libraries" phase in my Framework and try compile the client project that uses my framework the linker complains about missing symbols - I need to add FacebookSDK to the client project which is great: there is no possibility of conflicts if client apps wants to use Facebook.

然而,当我对Flurry静态库执行相同操作时,编译客户端项目时出现重复符号错误。这让我感到困惑,因为不是FacebookSDK.framework只是一个打包的静态库?

However when I do the same with Flurry static library I get duplicate symbols error when compiling client project. Which confuses me a bit, because isn't FacebookSDK.framework just a packaged static library?

ukaszs-iMac:FacebookSDK.framework lukasz$ file Versions/A/FacebookSDK 
Versions/A/FacebookSDK: Mach-O universal binary with 3 architectures
Versions/A/FacebookSDK (for architecture i386): current ar archive random library
Versions/A/FacebookSDK (for architecture armv7):    current ar archive random library
Versions/A/FacebookSDK (for architecture cputype (12) cpusubtype (11)): current ar archive random library

所以我的问题是:


  1. 为什么嵌入框架(如Facebook)的库没有链接到我的Framework项目产品,而库包含为.a文件?

  2. 如何在我的框架中包含.a文件以便它当使用我的框架的客户端应用程序也需要这个特定的静态库时,不会产生重复的符号错误?


解决方案

对于您正在描述的用例,您应该从应用程序链接到这些外部库,而不是您自己的框架。它可以是一个或另一个,但它不能同时存在。

For the use case you are describing, you should be linking to these external libraries from your application, NOT your own framework. It can be one or the other, but it can't be both.

如果您认为这些依赖项属于应用程序的责任,您可以将它们从链接二进制文件库和任何其他显式链接配置,只是将您的框架项目与这些框架和库的路径一起投影,以便它可以在编译时找到符号(但不是链接它们)(即库的路径)应该包括LIBRARY_SEARCH_PATHS)。

If you decide that these dependancies belong as the responsibility of the application, you would remove them from "Link Binary With Libraries" and any other explicit linking configuration, and just project your framework project with the path to these frameworks and libraries so it can find the symbols (but not link against them) at compile time (i.e. the path to the libraries should be included LIBRARY_SEARCH_PATHS).

这篇关于处理iOS Framework项目的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆