I am working on several iOS projects which will have a good bit of shared code, so I'm collecting that code in static libraries.
我正在开发几个iOS项目,这些项目将有很多共享代码,所以我在静态库中收集代码。
Now let's say I have 3 static libraries I'm working with:
现在让我们说我有3个静态库我正在使用:
- Lib A contains generic utility functions
- Lib B contains one set of classes
- Lib C contains a second set of classes
Lib A包含通用实用程序功能
Lib B包含一组类
Lib C包含第二组类
(and A is a dependency of both B and C)
(和A是B和C的依赖关系)
Now, my final project needs to utilize functionality from all three libraries. I know that A could be staticly linked with B, C, and my final project, but at that point I would get a linker error because there are multiple implementations of the same classes.
现在,我的最终项目需要利用所有三个库的功能。我知道A可以与B,C和我的最终项目静态链接,但在那时我会得到一个链接器错误,因为有多个相同类的实现。
How should a situation like this be handled?
应如何处理这种情况?
1 个解决方案
#1
6
For anyone else wondering about this, I've found that you can get the behavior I wanted by including header files with each library, but only linking with one.
对于其他任何想知道这一点的人,我发现你可以通过在每个库中包含头文件来获得我想要的行为,但只能链接一个。
In the example I outlined in my question, my primary project would link against A, B and C. However, to use A in libraries B & C, you can include the header files of A in B & C, but then only link against A in the root project.
在我在我的问题中概述的示例中,我的主要项目将链接到A,B和C.但是,要在库B和C中使用A,您可以在B&C中包含A的头文件,但是只能链接到A在根项目中。
If anyone has a better suggestion, please feel free to share.
如果有人有更好的建议,请随时分享。
As an aside, there's a project called Cocoapods that is an iOS dependency manager. It seems to be worth keeping an eye on.
另外,还有一个名为Cocoapods的项目是iOS依赖项管理器。这似乎值得关注。
#1
6
For anyone else wondering about this, I've found that you can get the behavior I wanted by including header files with each library, but only linking with one.
对于其他任何想知道这一点的人,我发现你可以通过在每个库中包含头文件来获得我想要的行为,但只能链接一个。
In the example I outlined in my question, my primary project would link against A, B and C. However, to use A in libraries B & C, you can include the header files of A in B & C, but then only link against A in the root project.
在我在我的问题中概述的示例中,我的主要项目将链接到A,B和C.但是,要在库B和C中使用A,您可以在B&C中包含A的头文件,但是只能链接到A在根项目中。
If anyone has a better suggestion, please feel free to share.
如果有人有更好的建议,请随时分享。
As an aside, there's a project called Cocoapods that is an iOS dependency manager. It seems to be worth keeping an eye on.
另外,还有一个名为Cocoapods的项目是iOS依赖项管理器。这似乎值得关注。