Xcode Multiple Static Libraries and Duplicate Symbols

懵懂的女人 提交于 2020-01-01 03:22:10

问题


I'm developing an iPad application which relies on two static utility libraries (libBFSDK & libBetfair-Platform). Both static libraries include AFNetworking. When I try to include the two static libraries in my iPad application, I get a linking error like:

duplicate symbol _OBJC_METACLASS_$_AFImageCache in:
/Users/osheas/Library/Developer/Xcode/DerivedData/Betfair-gnnjnwtovdmtoxakuxbjyvetciyy/Build/Products/Debug-iphonesimulator/libBFSDK.a(UIImageView+AFNetworking.o)
/Users/osheas/Library/Developer/Xcode/DerivedData/Betfair-gnnjnwtovdmtoxakuxbjyvetciyy/Build/Products/Debug-iphonesimulator/libBetfair-Platform.a(UIImageView+AFNetworking.o)
ld: 86 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

UIImageView+AFNetworking is part of AFNetworking. Both static libraries include AFNetworking. As a result, I get duplicate symbols for UIImageView+AFNetworking.

Anyone have ideas on a workaround for this? I have access to the source code for the two static libraries, but I'm still not sure how to solve this problem.

Thanks & please let me know if you need any other details,

Sean

PS - FWIW I'm running Xcode 4.5 & I need to be able to deploy to iOS 4.x devices.


回答1:


Since you have access to the source for the static libs, you could use the preprocessor to rename the AFNetworking symbols to something unique.

Add flags for each duplicate symbol to your "Other C Flags" build setting with the format

-AFNetworkingSymbol=UniqueAFNetworkingSymbol

This will still result in duplicate code, but should allow you to have multiple copies of AFNetworking without modifying the source.

More info

Ideally, most open source Obj-C code will move to solutions like CocoaPods and just specify dependencies instead of bundling them.




回答2:


Apparently, this is a relatively common occurrence. See https://github.com/square/PonyDebugger/issues/36 for more details.




回答3:


This is the simplest solution I have seen to this problem. I have tested it and it works. http://blog.sigmapoint.pl/avoiding-dependency-collisions-in-ios-static-library-managed-by-cocoapods/




回答4:


you check _AFImageCache has tow file in your project and remove one.

this can help you.



来源:https://stackoverflow.com/questions/13812007/xcode-multiple-static-libraries-and-duplicate-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!