Search code examples
iosiphonexcodellvmmach-o

Duplicate symbol in .framework and .a


I am developing a library .a file in Which i am using AFNetworking classes ... This library does also include one .framework which also using the AFNetworking classes (Adding this framework is optional)

Due to this I am getting following errors

duplicate symbol _OBJC_IVAR_$_AFHTTPRequestOperation._responseSerializer in:
    .../KonySDK.framework/KonySDK(AFHTTPRequestOperation.o)
.../Core.a(AFHTTPRequestOperation.o)

Options i have already considered is removing AF***.o from one of the file lipo -thin and ar -d -sv commands

Using this Link

But this library is configurable from server and adding that particular .framework is optional.

My question is ... Is there any otherway by which i can resolve this issue ? ALso i can would rather not prefer to remove .m files of AFNetworking from my library source as the entire process of generating library is fully automatic and configurable in many ways

I have also tried to resolve this by removing -all_load from other linker flags but this resulted in crash as categories of some classes are not loaded due to this.


Solution

  • You will get the duplicate symbol linker error whenever you have included a binary version of a class. The way to get rid of it is to remove the superfluous object.

    For building your library you only need the .h files of AFNetworking because those tell the compiler which classes and methods are available. You do not need to compile the AFNetworking source code because a .a file is essentially a collection of .o files which each contain the compiled versions of .m files.

    Libraries are not linked

    Only apps get linked and therefore need to have the symbols/objects present. i.e. if you provide your library without AFNetworking compiled in, then the developer using it needs to add AFNetworking via library, framework or cocoapod.