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.
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.
Related
My iOS project used a 3rd party (not open source) static library (i.e. libA.a), and this libA.a used CocoaLumberjack, it compiled CocoaLumberjack directly into itself, and the version of CocoaLumberjack is unclear.
Now I also want to use CocoaLumberjack to track logs in my program, and it will result duplicate symbol errors if I install CocoaLumberjack via CocoaPods.
Questions:
Is there a way to hide
the CocoaLumberjack symbols in libA.a so that Xcode won't report symbol errors?
Any other file logger libraries that can be recommended?
Now I am looking through symbols in libA.a, contrasting it with the source of CocoaLumberjack, and I am closed to find the version of CocoaLumberjack libA.a used, my next step should be only including header files of CocoaLumberjack in my project. It should work, but I don't like this way.
You can unpack the object files from the static library and repack it without the CocoaLumberpack object files.
Something like:
$ ar x libA.a
$ rm cococaLumberjackFile*.o # Whatever they are called
$ ar cr libA.a *.o
If the static library is fat (contains multiple CPU architectures) then this becomes much more difficult and involves lipo and much pain.
EDIT: Just go ahead and use CocoaLumberjack in your code and link with libA.a. It will provide the objects for both the 3rd-party library and CocoaLumberjack.
I have imported a new version of a framework in my SDK. Anyway, I am not able to build on iPhone 6 running iOS 9.0.1 because of the following error that's driving me crazy:
duplicate symbol _IPDJobStatus in:
/Users/akiki/Desktop/iOS 9 Test/MPSDK/iPD.framework/iPD(IPDDevice.o)
/Users/akiki/Desktop/iOS 9 Test/MPSDK/iPD.framework/iPD(IPDAdministration.o)
ld: 5 duplicate symbols for architecture arm7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is happening for the same symbol _IPDJobStatus being found twice in 5 files. The same is happening on iPhone 4S running iOS 9.1 with arm64 architecture. To import the framework, I deleted the old one from the project, imported the new one and check into the Link Binary with Library section wether the framework reference links to the correct updated file. Before asking I have tried to perform the following actions:
I searched for the duplicate symbol inside the project scope with no result.
I'm not importing a .m file by accident.
The Compile Sources of the Build Phases project settings doesn't include any duplicate file.
The framework headers references in Headers of the Build Phases project settings link to the proper files.
I tried to clean the project, empty the Derived Data folder, quit and relaunch Xcode.
I added the -ObjC linker flag (in this case the duplicate symbols goes from five to only one).
I switched the No Common Blocks compiler setting to NO, though it has the same error with or without it.
I created a new empty project and imported the framework there. In this case I was able to build, so the problem must resides in my SDK.
Could someone please give me some help?
You can check your project directory may be there available framework. If available then delete it.
I was able to solve the same problem with the following code.
Add this to the Library Search Paths in Build Settings and make sure you select recursive, delete other library paths which might be absolute paths.
$(PROJECT_DIR)
May be it will help you.
You can not make constant type variables of same name & type in two or more classes.
_IPDJobStatus is this constant type variable?
change it to some other name for different classes.
Here you can see the same issue
It means in you project multiple copy of same View Controller instance (i,e means duplicate).
Possible observation:
This IPDJobStatus variable contains in the class IPDDevice or IPDAdministration of the framework is duplicate. Please check this.
Note: You should not have/create a class which already have in any other framework either Xcode's default or 3rd party framework.
For example: UIkit framework have class name "UIApplication" (i.e UIApplication.h, and UIApplication.m). So, if you create you class name "UIApplication". this error will occur. Same case for also 3rd party framework.
I want to include Microblink's PDF417 framework into my library. Library project compile and work fine but when I use MyLibrary.a file in my application I've got "undefined symbols for architecture armv7" error. Any ideas? Can I include custom framework to library or this isn't possible.
Trojanfoe's answer is correct for your case. But in general, the answer depends on the type of the library inside the framework.
iOS/MacOS framework is a just a collection of a library together with all relevant header files. This makes including the library into other projects much easier, because the whole framework can be included at once, thus eliminating the need to modify linker and header search paths and linker flags.
Library itself can be either a static library or a dynamic/shared library. Framework can contain the library of any type, there are no limitations in that regard.
If the library in framework is static, then all the objects from that library are copied into target product at compile time. If the target product is a static library (MyLibrary.a in your case), additional linking with the framework in the application is not needed, because all the objects are contained in MyLibrary.a
If the library in the framework is dynamic, then objects from that library are loaded at load-time or run-time, not at compile time. Because of that, frameworks of that type need to be linked with end applications also.
In your case, pdf417 framework contains a dynamic library, which means you will also have to include that framework into your end application.
I'm a developer on Microblink's PDF417 SDK. The thing is, we can provide our library in any format. The format we have chosen in our Github repository is an .embeddedframework which contains a dynamic library together with all resource files because that makes including the framework into Application projects very simple. If you have a use case which requires a different format, we invite you to contact us on https://help.microblink.com/hc/en-us
A static library is just a collection of object files (a bit like a zip file without compression or hierarchy) and cannot hold information about any dependencies it might have.
Therefore you have to link the final executable binary against both your library and the dependent framework. The same applies if the dependency was a static library, dynamic library or framework.
My SDK uses a libssl.a library, but when I give it to a customer to use my SDK, they also uses a version of libssl.a and is causing duplicate symbol. Is there anyway to allow both to coexist?
Thanks
One option would be to rebuild libssl with a custom prefix on each symbol. I wrote a script for this purpose, which you can find here.
A simpler option might be to not link to libssl.a and require the customer to link to it instead. To do this, simply #import libssl's headers as usual, but leave libssl.a out from the link binary with libraries phase. The linker does not attempt to resolve symbols unless the target is an executable, so you will be able to compile a static library on this way without issues.
I currently have ShareKit in my project that is compiled as a static library. It is properly implemented. I also have implemented Amazon's AWS SDK by just adding their framework into my project.
It seems that the duplicate symbol is coming from Amazon's AWS SDK file, "AWSIOSSDK". This is what it looks like:
And that file is colliding with ShareKit's file, libShareKit.a. This is what that file looks like:
Anyway both of these files are ones that I haven't seen before. And it seems that some JSON files are colliding within them.
I have looked at other SO questions and they say to do some things with the compiled sources but none of these files are in the compiled sources from either library.
Here is the exact error Xcode gives:
ld: duplicate symbol _OBJC_CLASS_$_SBJsonParser
Anyway, does anyone have any ideas what I should do? My app does not compile unless I fix this issue.
Thanks!
You could go ahead and split a library archive into its object files and merge them again by leaving out the duplicates.
See the following walkthrough for getting an idea to manage that task:
Avoiding duplicate symbol errors during linking by removing classes from static libraries
Both of these have built SBJsonParser into their static libraries. This is not the correct way to build a static library. Each should build without SBJson and then you should link all of them together with SBJson. There are a couple of solutions:
Rebuild these libraries (or have their maintainers do so) to not include third-party libraries directly into a static library. This is the ideal solution.
Remove the incorrect SBJson files from the .a files using ar. You should be able to do this using ar -t to list the objects in the .a and then ar -d to delete the ones that shouldn't be in there. You could of course also ar -x to extract all the .o files and link them directly.
I had the same issue with FaceBookConnect Framework (let's call it project B) and my project (project A). Both were linking again JSON framework.
The solution is :
Go to Project B > Target > Build Phase > Remove JSON from the "Link Binary with libraries"
Make sure the JSON framework is still in the project (don't remove it) so project B can build
Build your project B you shouldn't get any error. The project should build but not embed the JSON frameworks symbols
Add both project B product (a framework) AND JSON framework in project A
Go to Project A > Target > Build Phase and check that both project B and JSON have been added to the "Link binary with libraries" section
Build your project A
Regards,