Duplicate symbol(s) for architecture(s) [arm7, arm64] - ios

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.

Related

Adding static library to project >> Undefined symbols

I have created a static library which I added to another project in the same workspace in XCode. The library builds fine, both for Simulator and an actual device.
All errors refer to classes in the library, so it's not about another framework.
I get two undefined symbols errors that both refer to "_OBJC_CLASS_$_Campaign"
When I build for an actual device I get Undefined symbols for architecture armv7s
When I build for a simulator I get Undefined symbols for architecture i386
I tried creating a fat library: same issue.
I toggled "build for active architecture only" on and off: doesn't help.
I deleted and rebuilt the XCode workspace: no solution.
I'm very sure I added the correct .m files to the "compile sources" of the library, and I properly added the library to the other project through "Link binary with libraries". I also tried just dragging the .lib to the Frameworks folder.
I added the header file of the .lib to the project.
I would be glad with any suggestion!
The problem is likely caused by the fact that your static library import something from another library.
You need to figure out what symbols are missing exactly and add library that defines them. Build log output should be very helpful in this regard.
EDIT: Based on discussion in comments, problem is caused by the fat that there's no implementation for Campaign class. Without implementation, compiler doesn't generate class and this results in linking error. There are no compile-time errors because interface of the class is declared though.
You should add such implementation, either in a separate Campaign.m file, or in one of already existing files.

Export an `OBJC_CLASS` from one static lib as part of another

I want to create a static library (actually, a framework, but I know how to do that part) that bundles up code from, among other things, another static library. However, the OBJC_CLASS exports from the original library end up as undefined symbols.
For example, in Xcode 5.1.1 (using default settings/choices at every step, unless otherwise specified):
Create a new "iOS Framework & Library Cocoa Touch Static Library" project named LibA.
Build (for either simulator or a real device, doesn't matter).
Create another new "iOS Framework & Library Cocoa Touch Static Library" project named LibB.
Drag libLibA.a from the LibA products to the Frameworks folder in the LibB project tree.
Drag LibA from the include directory next to the static lib to the top level of the LibB project tree.
Edit LibB.h as shown below.
Build (same target as before).
Create a new "iOS Application" (any type) project named AppC.
Drag libLibB.a from the LibB products to the Frameworks folder in the AppC project tree.
Drag LibB from the include directory to the top level.
Drag LibA from the first project's include directory to the top level.
Verify that LibA appears in the Link Binary With Libraries phase.
In any method of any class the wizard generated (e.g., -[MasterViewController awakeFromNib]), add (void)[[LibB alloc] init].
At the top of the .m file you just edited, add #import "LibB.h".
Build.
Here's the LibB.h promised above:
#import <Foundation/Foundation.h>
#import "LibA.h"
#interface LibB: LibA
#end
I get the following error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_LibA", referenced from:
_OBJC_CLASS_$_LibB in libLibB.a(LibB.o)
"_OBJC_METACLASS_$_LibA", referenced from:
_OBJC_METACLASS_$_LibB in libLibB.a(LibB.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Looking at the files, the problem is obvious:
$ nm -g libLibB.a
U _OBJC_CLASS_$_LibA
0000031c S _OBJC_CLASS_$_LibB
U _OBJC_METACLASS_$_LibA
00000308 S _OBJC_METACLASS_$_LibB
U _OBJC_METACLASS_$_NSObject
U __objc_empty_cache
The symbols for _OBJC_CLASS_$_LibA and _OBJC_METACLASS_$_LibA are exported as undefined.
I can reference methods, C functions and structs, globals, etc. from LibA. Even categories on Foundation objects (as long as I do the category-dummy trick). It's only the class and metaclass objects that I can't figure out how to export.
Here's what I've tried to fix it:
Turn off Dead Code Stripping (in all three projects).
Add -ObjC as an extra linker flag (in all projects). (This makes no sense for static libs, and all it does is give you a warning error telling you exactly that, but everyone suggests it to me.)
Create an "Exported Symbols File" (for LibB). (This also only makes sense for dynamic libs.)
Pass ${PROJECT_DIR}/libLibA.a as an "Other Linker Flags" (for LibB) instead of adding libLibA as a framework (in case -lLibA is processed differently from libLibA.a).
What I've tried that I still think may be on the right path, but I'm not sure:
Try to figure out appropriate libtool options that have no corresponding settings in Xcode. (I can wrap it in a Makefile, or and Xcode custom build step, if necessary.)
Enable "Perform Single-Object Prelink", then add ${PROJECT_DIR}/libLibA.a to "Prelink libraries". I get warnings about duplicate symbols and then success but with an empty libLibB.a, so obviously there's something else I need to do. I've done this with .dylibs and dynamic Frameworks on OS X, and there wasn't anything else I needed to do there… but never with static libs.
Workarounds that I know about (and I'll use one of these if there's no real solution):
Require that anyone who wants to use LibB also has to add LibA to their project. And, in particular, the pre-built copy of LibA that we provide.
Distribute LibB as source to be included in your project, instead of a static lib and headers.
Manually ar libLibA.a and LibB.o, then ranlib like it's 1999 (although the docs say this doesn't work, it seems to).
(None of these are too terrible for my simple test project, but in real life, this is not an open source project, that LibA is actually 80 different libs from 3 different projects, and some of the LibA code builds fat armv7/armv7s (which means ar doesn't work on it…), and we're planning to do the usual hack of lipo'ing together the simulator and native builds and making a framework out of them, all of which makes things more of a problem.
I think I may have solved it with single-object prelink (basically this means it does an ld -r to build a giant object file, then passes that to libtool), although I'm still not sure, and I don't love the solution. So, I will post what I've got as an answer, but hope someone else comes along with a better answer.
To get single-object prelink to work, you need to (in LibB):
Add libLibA.a as a Framework.
Make sure it does not appear in the Link Binary With Libraries build phase.
Set "Dead Code Stripping" to No.
Set "Don't Dead-Strip Inits and Terms" to Yes.
Set `Perform Single-Object Prelink" to Yes.
Set "Prelink libraries" to ${PROJECT_DIR}/libLibA.a
Set "Preserve Private External Symbols" to Yes.
(The second step is what I was doing wrong earlier…)
Unfortunately, this seems to break the dependency rules completely, so that every build recompiles every .m (and .pch) that's part of the target, even if nothing has changed.
Other than that annoyance, this seems to work for both AppC and my real project just fine.
AppC does not need "Preserve Private External Symbols"; my real project does. I believe this is because one of the third-party libraries does an ld -r with an empty -exported_symbols_list explicitly to "transform all symbols to private_extern. Otherwise, class objects don't end up that way. However, I'm not 100% sure I understand this one.
Adding this to Other Linker Flags appears to work
-force_load $(CONFIGURATION_BUILD_DIR)/libLibA.a

Significance of -ObjC value in Other Linker Flags: GMaps SDK

I was trying out google maps sdk integration with iOS 6.1. I am successfully able to populate gmap on iOS simulator by using instructions given on
GMaps for iOS starting guide
Then what the issue with it:
It works great when I use it as a separate project. But when I club the above project code with my existing application, then it behaves weird, and all the errors generates due to inclusion of -ObjC value in Other Linker Flags in Build Settings.
Error
duplicate symbols for architecture i386
When I skip step 7 (GMaps iOS), it doesn't give errors. Due to exclusion of -ObjC value, it doesn't able to identify a specific GMaps library class and its method:
[GMSCameraPosition cameraWithLatitude:longitude:zoom:]: unrecognized selector sent
My iOS application background:
Using a third party library SUP (Sybase Unwired Platform). Connecting SAP to iOS application. I guess there is something ambiguous with SUP environment enablement (Build settings) when I am trying to add GMaps library.
Seeking for your advices.
Thanks!
There many posts on SO about the duplicate symbols for architecture i386 error. Usually it means that you defined the same symbol twice in the one namespace. The last time I got this error was because I accidentally included a .m file instead of .h header file.
Have you checked the Build Architecture?
Try setting Build Active Architecture Only to Yes.
I was facing the same issue Today! -ObjC linker flag - When trying to add it to "Other Linker Flags" I get an error
I solved my problem, Here is what I'd suggest. Take your original project (without Gmaps and with SUP) and add the -ObjC flag to it. Are you still getting an error? If so, take Gmaps out of the equation. If you are still getting an error check in the warnings about which files it is warning you about. My problem was that I had two files libGoogleAnalytics.a and libGoogleAnalytics_debug.a and for some reason they could not coexist with the -ObjC.
Long story short, you need to find what libraries Gmaps is using that you already have in your project and remove one of them.
Please try this…
step 1: Add '-ObjC' to other linker flags in 'Build Settings' of your 'target' only not to the 'project'

Ho can I use adMob library for iOS without using -all_load linker flag

I'm adding adMob provide by google to my iOS app and I'm stuck on this part of the installation:
Add -all_load under Other Linker Flags in the project build info
If I add that flag, then another third party library breaks giving me the error message:
ld: duplicate symbol _vw_chartype_table_p in /Users/josh/ Projects/app/libs/libvt_universal.a(vw_ctype-3279EF26D0C25F3A.o) and / Users/josh/Projects/app/libs/ libvt_universal.a(vw_ctype-34AB9EC0B46D954C.o) for architecture i386
Is there any way to use the adMob library without using -all_load? For example, I've tried -force_load $(SOURCE_ROOT)/adMob/libGoogleAdMobAds.a
but
ld: file not found: /Users/USERNAME/Desktop/latest/bbbb/APPNAME/adMob/libGoogleAdMobAds.a
The reason Google suggests using -all_load is that they are using categories in their code, and Objective-C libraries with categories are not properly loaded by the llvm linker (well that was the case in 4.3 xcode, not sure about 4.4 with the newer clang).
So, I guess if you are brave you can try to just remove the all_load flag. It should build fine. If the bug is NOT fixed, what will happen is when you run your code, it will crash, since none of the categories the library uses will have been loaded. This might be a good thing to do in any case, as your project should build, and if it does not you can fix those problems first.
What I do suggest you do is use -force_load, which has llvm load the categories in the adMob library (among other things). To use it you MUST have a fully qualified path (ie starts at '/') to the library. Obviously if you use Terminal and run:
ls -l /Users/USERNAME/Desktop/latest/bbbb/APPNAME/adMob/libGoogleAdMobAds.a
its going to fail. So enter the proper path - hard coded - for now to just see if you can get the project to first build, then run. If it does you can later figure out what is the appropriate $(VAR) to use to find it inside your project.

Duplicate Symbol linker error

I have an existing app in which I added the json-framework. Now it won't compile due to a duplicate symbol linker error.
The error seems to be due to the installed Millenial Media ad network SDK which also links to the json-framework. It seems the json-framework must be already embedded in MMs .a static library file. If I dont add the SDK then I cant import the json-framework for use in my own code, but when I do the compiler raises this exception.
ld: duplicate symbol _OBJC_IVAR_$_SBJsonParser.maxDepth in /users/laptop/Developer/sandbox/testapp_sources_add_owntracking/testapp/AdNetworkLibs/MillenialMedia/libMMSDK.a(SBJsonParser.o) and /Users/laptop/Library/Developer/Xcode/DerivedData/testapp-bjxtaanqoewrondmjnucarxebkka/Build/Intermediates/testapp.build/Debug-iphonesimulator/testapp.build/Objects-normal/i386/SBJsonParser.o for architecture i386
collect2: ld returned 1 exit status
You can add the json framework header files without adding the json class implementation files. If these classes are in another library, then they will be linked with that library.
In your project, you have SBJsonParsor added twice.
This might have happend as some of the library (source) you are using (added to project) already have SBJsonParsor added without your active knowledge about the same.
You need to check your project hierarchy and remove one of the reference.

Resources