12


Some background - I've built a custom Framework using Diney's guide at http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/

Its built for both armv6 / armv7 , its an ARC-based framework, compiled with a depolyment target of 4.3.

When i put the resulting framework in a 5.0 project it works great, but when i put it in a 4.3 project (ARC or non-arc, doesnt matter), i get the following which i can't really understand ...

I've also tried adding libarclite.a manually but it didn't change anything.

ld: duplicate symbol _objc_retainedObject in /Users/freak4pc/Project/MyFramework.framework/MyFramework and /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a(arclite.o) for architecture armv7 Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang failed with exit code 1

Would appreciate any help on this.
Thanks
Shai

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
  • Why not just build a static library like everybody else does for iOS? The approach you've linked to seems like something of a hack, so I'm not surprised that things may not be linking as intended. – Brad Larson Dec 04 '11 at 17:13
  • Uhm i just got a suggestion that Static Libraries aren't as flexible. Could you link me to some resources about this perhaps? – Shai Mishali Dec 04 '11 at 17:19
  • I'm not sure what "less flexible" would mean in this case. If you have the code for your library, there's little difference in usage between a static library and a framework. If you're distributing the precompiled library, all you have to do is make sure that the headers are available as well. For an example of this, see the Core Plot library: http://code.google.com/p/core-plot/ , which uses a framework for Mac and static library for iOS. I don't recall it being hard to set up the static library compilation there. – Brad Larson Dec 04 '11 at 22:11

2 Answers2

15

I'm struggling with the same problem. The workaround is so set the deployment target of your framework to iOS5 (check if that doesn't make other problems though).

Then you must use ARC in the master project if targeting iOS4, else libarclite will be missing. My solution will be to supply two frameworks, depending if they use ARC or not.

Here's two links to Apple's dev forum with a little bit more info: https://devforums.apple.com/message/539344#539344

https://devforums.apple.com/message/588316#588316

Update: There is a better way. Just build your static library with iOS5 minimum target, and manually add /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a (and /Developer/usr/lib/arc/libarclite_iphonesimulator.a) if your project is not using ARC and needs iOS4-support.

Update 2: Actually, just use the linker flag -fobjc-arc ; this will link libarclite with the library if it's not already in there. Best solution.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
steipete
  • 7,581
  • 5
  • 47
  • 81
  • Thank you ,It's a better way. manually add /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a (and /Developer/usr/lib/arc/libarclite_iphonesimulator.a) – HelloWorld Feb 26 '12 at 08:09
2

Wow that was a hard ride but i finally solved it!

What sparked the final idea was @steipete's comment , Its a bit of a complex situation so i'll try to explain it for anyone who might've crossed this issue as well.

  1. Compiling a ARC-enabled framework on iOS 4.3 will automatically attach libarclite.so to "bridge" 4.3 ARC with 5.0 ARC. When this framework was imported to a 4.3 project, arclite was actually linked twice - once for the framework (which is 4.3), and once for the project itself - which caused the "duplicate symbol" error, meaning the framework has to be compiled on 5.0, and the project can be 4.3. But then ;
  2. My framework is using @mattt 's AFNetworking to perform HTTP Requests and JSON parsing of different APis. AFNetworking automatically checks while compiling if your target is iOS5 , and if it is, it uses NSJSONSerialization, otherwise it would fall back to any imported JSON library such as JSONKit.
  3. When compiling my AFNetworking-enabled Framework for iOS5 (to avoid problem no.1), it would automatically attach NSJSONSerialization, which will cause an exception on 4.3 projects, meaning you would have to manually look for the compile directions and remove the calls to NSJSONSerialization before compiling, so it would automatically fall back to the 4.3-compatible library (in my case JSONKit) . That compilation condition is found on AFHTTPClient.m and AFJSONRequestOperation.m (e.g. #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6)
  4. After removing those conditions, i successfully compiled my framework for iOS5 with JSONKit instead of NSJSONSerialization, and was successfully able to use it in my iOS4.3 project.

Hope this would help anyone else who might struggle with this for a couple of days like myself :)

Shai.

Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
  • Honestly, I don't see your answer adding more value (#2,#3 and #4 are not even relevant to the question), so it leaves a bitter taste that you marked _your own_ answer as correct. You also missed to explain the problematic that your master project must use ARC if you use ARC w/o adding libarclite.so in a subproject, if it needs to support iOS 4.x. – steipete Dec 08 '11 at 15:44
  • Im sorry but i really do not agree with you. I have no problem to mark your answer as "the right one" (i dont get points for marking my own) - but I do think my answer is more complete as it explains the entire process. 2-3-4 were what caused me not to be able to use your tip , so they are VERY relevant. Also, i do believe its my question so calling whats relevant and what not it my choice. I do appreciate your help a lot, but i think your comment here was out of place. – Shai Mishali Dec 08 '11 at 16:02
  • 1
    Have to agree with steipete. Your "answer" may be relevant to your project but is irrelevant to the issues we are seeing. – wuf810 Mar 04 '12 at 13:52
  • @wuf810 As i said, as i opened the question, i believe i know best what is the answer that helped me most, and more than that - I know what is the info i needed to solve the problem. Again, i'll say - voting my own answer doesn't give me any points, and i did eventually mark his answer as the right one, so i definitely don't see a downvote making any sense. Thanks for your "kind" comment anyways. – Shai Mishali Mar 04 '12 at 14:19
  • Without step 3 , I wouldnt've been able to compile the framework. The info is relevant to my specific situation in which i had AFNetworking in the project. – Shai Mishali Mar 04 '12 at 14:22