seanoshea
seanoshea

Reputation: 6136

Xcode Multiple Static Libraries and Duplicate Symbols

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.

Upvotes: 7

Views: 5629

Answers (4)

Theis Egeberg
Theis Egeberg

Reputation: 2576

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/

Upvotes: 0

Nate T
Nate T

Reputation: 2918

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.

Upvotes: 3

seanoshea
seanoshea

Reputation: 6136

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

Upvotes: 0

Chu Chau
Chu Chau

Reputation: 70

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

this can help you.

Upvotes: -1

Related Questions