链接具有公共静态库的静态库的正确过程是什么? [英] What is the correct process for linking static libraries that have common static libraries?

查看:23
本文介绍了链接具有公共静态库的静态库的正确过程是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个名为 Silicon 的静态库,用于我的所有 iOS 应用程序.

I am working on a static library, called Silicon, that I use for all of my iOS apps.

因为我不想创建一个难以维护的庞大静态库,所以我创建了许多作为子模块附加的较小的静态库.

Because I don't want to create one massive static library that could become hard to maintain I create lots of smaller static libraries that I attach as submodules.

截至撰写本文时,Silicon 的依赖树如下:

As of the time of this writing the dependency tree for Silicon is as follows:


|
|==> FDKeychain
|==> FDDataClient
      |
      |=> FDRequestClient
           |
FDFoundationKit
|==> FDSQLiteDatabase
      |
      |=> FDFoundationKit

如您所见,FDRequestClient 和 FDSQLiteDatabase 都将 FDFoundationKit 作为公共静态库.

As you can see both FDRequestClient and FDSQLiteDatabase have FDFoundationKit as a common static library.

似乎发生的是,当使用 Silicon 构建项目时,它会将 Silicon 的所有目标依赖项构建到项目构建目录中.同样的事情发生在 FDDataClient 和 FDSQLiteDatabase 上.因此,在某些时候,FDRequestClient 中的 FDFoundationKit 被构建并复制到构建目录以及 FDSQLiteDatabase 中的 FDFoundationKit.最后构建的任何一个只会覆盖前一个.

What seems to happen is that when a project using Silicon is built it builds all of Silicon's target dependencies to the projects build directory. The same thing happens for FDDataClient and FDSQLiteDatabase. So at some point FDFoundationKit from FDRequestClient is built and copied to the build directory as well as FDFoundationKit from FDSQLiteDatabase. Whichever one is built last just overwrites the previous one.

纯属运气,FDFoundationKit 并没有发生任何严重的变化,以至于 FDRequestClient 和 FDSQLiteDatabase 不能总是使用相同的版本,但我不能保证它会永远这样.

Just by sheer luck FDFoundationKit hasn't been changing in any serious ways such that FDRequestClient and FDSQLiteDatabase can't always be using the same version but I can't guarantee it will be like this forever.

我试图弄清楚 Silicon 是否有办法指定要使用的 FDFoundationKit 版本,因此 Silicon 有责任确保所使用的版本适用于 FDRequestClient、FDSQLiteDatabase 和我添加的任何其他依赖项未来.

I am trying to figure out if there is a way for Silicon to specify which version of FDFoundationKit to use so it can be Silicon's responsibility to ensure that the the version used will work for both FDRequestClient, FDSQLiteDatabase and any other dependencies I add in the future.

我知道 CocoaPods 试图解决这个问题,但我不想让某人为了让我的库工作而必须设置所有这些.如果我能找到让 Silicon 定义使用哪个版本的 FDFoundationKit 的方法,一切都会完美运行.

I know CocoaPods attempts to solve this problem but I do not want to make someone have to setup all of that just to get my library working. If I could just find someway of having Silicon define which version of FDFoundationKit to use everything would work perfectly.

推荐答案

这个问题似乎只有两个答案:

There looks to be only two answers to this problem:

1) 使用 CocoaPods 或 Carthage 等依赖管理器.

1) Use a dependency manager like CocoaPods or Carthage.

2) 您发布的任何静态库或框架都不应具有任何目标依赖项.它们应该链接到您拥有的任何依赖项,并且集成您的库的人员有责任同时集成所需的依赖项.

2) Any static libraries or frameworks you release should not have any target dependencies. They should link against any dependencies you have and it is the responsibility of person integrating your library to also integrated the required dependencies.

这篇关于链接具有公共静态库的静态库的正确过程是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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