iOS4.1 SDK中的单个库中的重复符号

我正在开发一个iPhone应用程序。 我对Xcode不熟悉,请耐心等待。 我有iOS 4.1设备SDK。 当我在“Active …”下拉框中select“Simulator”时,我的应用程序将无错地编译并运行在iPhone模拟器中。

但是,当我在下拉框中select“设备”时,出现以下有关重复符号的链接器错误:

Ld build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone normal armv6 cd /Users/isaacsutherland/fydp/PineCone/PineCone setenv IPHONEOS_DEPLOYMENT_TARGET 4.1 setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk -L/Users/isaacsutherland/fydp/PineCone/PineCone/build/Debug-iphoneos -L/Users/isaacsutherland/fydp/PineCone/PineCone/../3rd/libGHUnitIPhone -F/Users/isaacsutherland/fydp/PineCone/PineCone/build/Debug-iphoneos -filelist /Users/isaacsutherland/fydp/PineCone/PineCone/build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone.LinkFileList -dead_strip -all_load -ObjC -miphoneos-version-min=4.1 -framework Foundation -framework UIKit -framework CoreGraphics /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Core.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Network.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Style.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UI.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UICommon.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UINavigator.a -framework QuartzCore -framework CFNetwork -framework MobileCoreServices -framework SystemConfiguration -lz.1.2.3 /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a -lGHUnitIPhone4_0 -o /Users/isaacsutherland/fydp/PineCone/PineCone/build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone ld: duplicate symbol _RedirectionLimit in /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a(libASIHTTPRequest.a-armv6-master.o) and /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a(libASIHTTPRequest.a-armv6-master.o) collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1 

该错误是奇怪的,因为它抱怨_RedirectionLimit被发现两次 – 在同一个文件! libClientDal.a(libASIHTTPRequest.a-armv6-master.o)是违规的库。 有人能帮我理解发生了什么吗? 这个图书馆怎么能够正确编译呢? 或者也许链接器试图包含两个相同的库?

在这个类似的问题提供的解决方法不适合我。

如果你需要更多的信息,我会很乐意提供它 – 正如我所说,我是Xcode开发的新手。

当你有一个编译成静态库的项目并互相引用时,你必须考虑两个不同的问题:

  • 一个项目的Direct Dependencies通知Xcode哪个项目相互依赖,所以它知道在项目的依赖性发生变化时重新编译项目。

  • 一个项目的链接库实际上包含在它的目标代码中。

简而言之,您的直接依赖关系networking可以像您想的那样纠结,但您必须小心地将每个项目的代码链接到应用程序可执行文件中一次

基本上,我的问题是我有3个项目A,B和C,依赖关系看起来像A => B,A => C,B => C。 我将libC.a链接到A和B,所以链接器抱怨重复的代码。

您需要更改的configuration资料位于每个项目目标的“目标信息”页面上。

当我使用-all_load链接器标志时,发生了这种情况,这会强制链接器从所有库中加载所有符号。 Three20项目说你应该使用它,因为否则类别不会被加载,你会得到一个运行时exception。 我删除了该标志,并为每个需要它的库(Three20库)添加了-force_load标志。 另请参阅: -all_load链接程序标志是做什么的?

我有几个应用程序需要embedded一个使用ASI和TBXML的小型自定义库。 这些应用程序的一些有他们自己的版本的图书馆。 为了避免重复的符号问题,我复制了每个库的目标,删除导致问题的.m文件。 希望能帮助到你。