7

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.

seanoshea
  • 5,556
  • 3
  • 20
  • 28
  • surely the answer is to only import the headers in the sub project? Linking to the static libraries would only be done in the iPad app? – Max MacLeod Feb 14 '13 at 09:37

4 Answers4

3

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.

Nate T
  • 2,658
  • 1
  • 20
  • 14
  • Good point. I've been using CocoaPods for the past month or so and have found it very useful for figuring out dependencies between libraries. – seanoshea Jun 07 '13 at 08:26
  • I'm looking for a way to do this to all symbols in an SDK I'm outputting, without having to add a new flag every time I add a new file, so that we can ensure that there will never be a naming conflict. – Matt Foley Nov 20 '13 at 17:52
0

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

seanoshea
  • 5,556
  • 3
  • 20
  • 28
0

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/

Theis Egeberg
  • 2,556
  • 21
  • 30
-1

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

this can help you.

Chu Chau
  • 70
  • 1
  • 4
  • I'm assuming you mean UIImageView+AFNetworking instead of AFImageCache? There are two versions of UIImageView+AFNetworking in the application. Each static library includes AFNetworking which includes UIImageView+AFNetworking. I'll update the question to make sure this is more clear. – seanoshea Dec 11 '12 at 05:02