如何避免"重复的符号QUOT;以x code错误与共享静态库? [英] How can I avoid "duplicate symbol" errors in xcode with shared static libraries?

查看:182
本文介绍了如何避免"重复的符号QUOT;以x code错误与共享静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有静态库A,B和C分为X $ C $Ç项目。 A和B取决于C.当我建立一个依赖于A和B的iPhone项目,我得到一个重复的符号(从C)A和B中检测到我如何组织这三个静态库,所以我一个链接错误可以将它们包含在另一个X code项目没有遇到这个问题?

I have static libraries A, B and C organized into Xcode projects. A and B depend on C. When I build an iPhone project that depends on A and B, I get a linker error that a duplicate symbol (from C) was detected in A and B. How can I organize these three static libraries so I can include them in other Xcode projects without experiencing this error?

推荐答案

卡尔的答案是正确的,但错误的原因:这里居然没有错,静态库联系在一起,因为我们可以用卡尔自己的样品看看。建立卡尔的样本code,然后做到这一点:(我用的libtool因为这是X code使用)

Carl's answer is right, but for the wrong reasons: there's actually nothing wrong with linking static libraries together, as we can see using Carl's own sample. Set-up Carl's sample code and then do this: (I use libtool because that is what XCode uses)

neutron:libtest jamie$ libtool -o a2.a a.a c.a
neutron:libtest jamie$ libtool -o b2.a b.a c.a
neutron:libtest jamie$ gcc main.o a2.a b2.a -o app2
neutron:libtest jamie$ ./app2
a
c
b
c
neutron:libtest jamie$ 

此链接a2.a和b2.a与main.o.据卡尔,这是有机磷农药问题的根源,并APP2不应该链接。当然,它确实。连接器是足够聪明,忽视了同一个文件的两个实例。我们可以看到,无论a2.a和b2.a包含c.o:

This links a2.a and b2.a with main.o. According to Carl, this is the source of OPs problem, and app2 shouldn't link. But of course it does. The linker is smart enough to ignore two instances of the same file. We can see that both a2.a and b2.a contain c.o:

neutron:libtest jamie$ ar -t a2.a
__.SYMDEF SORTED
a.o
c.o
neutron:libtest jamie$ ar -t b2.a
__.SYMDEF SORTED
b.o
c.o

然而,它连接的罚款。

Yet it links fine.

问题是,我认为,联系到通用二进制代码,无论是PPC / x86的通用程序,或用于ARMv6 / ARMv7的iPhone通用二进制代码。这里的问题是,有与类别和修复bug(添加-all_load到连接标志)是一个修复程序仅适用于单一的架构。使用-all_load打破忽略了为多种体系结构定义的符号连接子能力,你有你的重复的符号错误。

The problem is, I believe, linked to Universal Binaries, either PPC/x86 universal binaries, or armv6/armv7 iPhone universal binaries. The problem here is that there is a bug with categories and the fix (add -all_load to the linker flags) is a fix that only works for single architectures. Using -all_load breaks the linkers ability to ignore symbols that are defined for multiple architectures, and you have your duplicate symbol error.

我写了一篇关于它href=\"http://blog.binaryfinery.com/universal-static-library-problem-in-iphone-sd\"> 包括比使用-all_load更好的解决方案

I wrote about it here including a better solution than using -all_load.

这篇关于如何避免"重复的符号QUOT;以x code错误与共享静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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