ld: duplicate symbol _objc_retainedObject on iOS 4.3 , but not on iOS 5.0

后端 未结 2 792
囚心锁ツ
囚心锁ツ 2021-02-07 21:48


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 armv

2条回答
  •  旧巷少年郎
    2021-02-07 22:23

    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.

提交回复
热议问题