简体   繁体   English

在Xcode静态库中包含框架?

[英]Include framework in Xcode static library?

In short: 简而言之:

Is there a way to create a static library in Xcode such that when clients link with that library, they also link with the frameworks upon which that library depends? 有没有办法在Xcode中创建静态库,以便当客户端链接到该库时,它们还链接到该库所依赖的框架?

The problem: 问题:

We have a shared Xcode project which contains multiple static library targets containing all of our common code. 我们有一个共享的Xcode项目,它包含多个包含所有常用代码的静态库目标。 Eg, If a project wants to use the shared networking code, all they should have to do is link in our Network library. 例如,如果项目想要使用共享网络代码,他们应该做的就是在我们的网络库中链接。

The problem is that the libraries don't seem to "include" the frameworks on which they depend. 问题是库似乎并没有“包含”它们所依赖的框架。

Eg, our Sound library uses the AudioToolkit.framework. 例如,我们的Sound库使用AudioToolkit.framework。 Even when the Sound library includes AudioToolbox.framework in the list its linked libraries, clients get linker errors when linking with Sound if they don't also directly link with AudioToolkit.framework. 即使Sound库在其列表链接库中包含AudioToolbox.framework,客户端在与Sound链接时也会遇到链接器错误,如果它们也不直接与AudioToolkit.framework链接。

This is a maintenance hassle because every time a library's framework dependencies change we have manually go change the list of linked frameworks in all dependent projects. 这是一个维护麻烦,因为每次库的框架依赖关系发生变化时,我们都会手动更改所有依赖项目中链接框架的列表。

Is this supposed to work? 这应该有用吗? Is there a better way? 有没有更好的办法?

Thanks! 谢谢!

In short: no, a static library is just a bunch of .o files 简而言之:不, 静态库只是一堆.o文件

A solution would be to refactor your common code into "static frameworks", see there for a possible solution. 一个解决方案是将您的公共代码重构为“静态框架”, 在那里寻找可能的解决方案。

A new answer to this question would be, yes it's possible: use cocoapods! 这个问题的新答案是,是的,可能:使用cocoapods! :) :)

http://cocoapods.org http://cocoapods.org

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

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