我正在编写一个依赖于静态第三方库Lib的iOS框架Foo,并且在获取正确链接方面存在问题.
如果Foo是一个静态库,我不会将它与Lib链接,只能将主项目与它们连接起来.但是这种方法似乎不适用于框架:链接器抱怨Lib缺少符号.
所以我采取了另一种方法并将Foo与Lib联系起来.现在链接器很高兴,但有一个明显的问题:如果主项目使用Lib出于自己的原因并链接Foo和Lib,我会得到重复的符号:
Class <Something> is implemented in both <Here> and <There>. One of the two will be used. Which one is undefined.
我知道我可以停止将该应用程序与Lib联系起来,一切都会好的,但我想把事情做对.怎么样?
解决方法
我能够为框架工作,尽管文档说它也应该适用于静态库.
我所做的是将主项目与Foo和Lib联系起来.现在Foo有“缺少符号”的错误.选择Foo目标并转到Other Linker Flags.添加-weak_framework Lib和presto!链接器将停止抱怨.重复的符号运行时错误消失了.
根据docs:
The
-weak_framework
option tells the linker to weakly link all symbols in the named framework. If you need to link to a library instead of a framework,you can use the-weak_library
linker command instead