duplicate symbols for architecture i386 clang

Objective CIos5Admob

Objective C Problem Overview


I've seen several posts on google and stackoverflow related to this error, I've read all of them but still fetching the problem , I will be glad for a solution. Here is the error mesage I recieve when compiling ...

> directory not found for option '-L/Users/somefolder/Documents/Bharat/MyApp copy/GoogleAdMobAdsSDK' duplicate symbol OBJC_CLASS$_AppDelegate in: /Users/madept/Library/Developer/Xcode/DerivedData/Alpha-dvvymdlmzseytagllsmbbrxdgutz/Build/Intermediates/Alpha.build/Debug-iphonesimulator/Alpha.build/Objects-normal/i386/AppDelegate-56890B6B994A4284.o

Thanks.

Objective C Solutions


Solution 1 - Objective C

Another reason this error often happens is accidentally importing the .m file instead of the .h.

Solution 2 - Objective C

Steps:

  1. Check Build phases in Target settings.
  2. Check if any file exists twice or once.
  3. If file exist twice delete one. If not delete file in the bottom which is the latest one.
  4. Build again.

Solution 3 - Objective C

Just to add to the possible solutions.

In my case I had accidentally declared and initialized a variable in a header file.

For example this is wrong:

MyFile.h

#import <Foundation/Foundation.h>

NSInteger const ABCMyConstant = 6;

It should be:

MyFile.h

#import <Foundation/Foundation.h>

NSInteger const ABCMyConstant;

MyFile.m

#import "MyFile.h"

NSInteger const ABCMyConstant = 6;

Solution 4 - Objective C

Go to Build Setting and search for No Common Blocks and set it NO. And build again you will not get this error again.

Solution 5 - Objective C

I found that I was getting the error when I had a const declared in a .m file with the same name as another const in another .m file. Both files #included the same parent file.

Solution 6 - Objective C

I just experienced this after recreating a model class for Core Data. The menu option to create object classes created a duplicate model class. once i removed the dupe, error gone...

Solution 7 - Objective C

Linker errors are always showing a problem regarding to a library usage or import issues.

Sometimes the error happens when you have imported a .m file instead of a .h file.

Please check your code and look for a .m import statement in one of your header files (.h extension), I had a similar issue and 14 duplicate symbol error raised.

Check if you have imported ViewControler.m instead of its .h,So it has to be this way :

    import "ViewController.h"

and your AppDelegate.h should be something like this :

import "UIKit/UIKit.h"
import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) ViewController *mainController;
@end

Always remember to import header files not a .m

Solution 8 - Objective C

If other people have tried all the other answers and it still isn't working, try opening up the .xcodeproj file with your favorite text editor and searching for the name of the class that's giving you trouble. Make sure you close Xcode before doing this. In the file, there should be one line for the .h and another line for the .m. If there are duplicates, remove them, save the file, and re-build.

Solution 9 - Objective C

I had this issue with a framework that I knew worked in another project. I had copied the files from the other project and added it to this one. Then when building I got 76 duplicate errors.

The simple solution for me was removing -ObjC from Other Linker Flags. The previous project did not have that. Once I did that, the warning disappeared and the project built successfully.

Solution 10 - Objective C

I got this error when I had a static library included in the main project while also including a second library that also had a reference to the library. That's pretty confusing, so maybe this is clearer.

MyWorkspace

  • Main Project
    • Reference to library 1
    • Reference to library 2
  • Library 1
  • Library 2
    • Reference to library 1

I removed the reference to library 1 from the main project and the error went away.

Solution 11 - Objective C

Another reason can be that the project is targeted at a simulator instead of a real device when building a distribution-version. That also causes this error message.

Solution 12 - Objective C

Finally i got the solution-

  1. remove all the reference of AdMob SDK, which i added(also delete from workspace as well).
  2. clean your project
  3. [follow this link to add AdMob again][1]
  4. clean and rebuild [1]: https://developers.google.com/mobile-ads-sdk/docs/admob/ios/quick-start

Solution 13 - Objective C

Easiest way to resolve this is issue Xcode 7.0 or latter just change no Common Blocks to NO it will solve your problem try this Project Target > Build Setting > No Common Blocks, i change it to NO.

Solution 14 - Objective C

In certain cases you can also get a "duplicate symbols for architecture..." error due to the fact that you accidentally declared a constant (const) with the same name in two different files.

Solution 15 - Objective C

I had it where I defined the same C function twice. In two different .m files. Simply remove one of the definitions and voila.

Solution 16 - Objective C

I tried cleaning the project, erased all derived data. Nothing worked. Atlas, this worked for me.

enter image description here

Another reason can be that the project is targeted at a simulator instead of a real device when building a distribution-version. That also causes this error message.

Solution 17 - Objective C

It was different for me, I copied over the class implementation methods as is and the iVars were also copied over... so in the world of iVars there are two sets and the compiler kept complaining about duplicate ivars before linking the *.o files.

reading the output helped so removed all the duplicating ivars... thanks to the new feature where you need not @synthesize all your properties... the error went away...

Solution 18 - Objective C

I got the same error when setting up OCMock. I fixed it by add the libOCMock.a in 'Copy Files' section of Building Phase

Solution 19 - Objective C

I had this error after I copy & paste a test file into the project, forgetting to change the name of the interface and implementation lines:

@interface TDInputValidationsTests : XCTestCase

and

@implementation TDInputValidationsTests

Silly mistake... I also suggest looking at the "build phases" tab on the project to check for duplicates. Deleting the derived data and making a clean-build might help as well.

Solution 20 - Objective C

I imported files from another project, it had main.m file as well. So overall I had two main.m files, deleting one resolved the issue for me.

Solution 21 - Objective C

Sometimes believe it or not, Xcode screws up the project file. The only solution we found was to manually remove every reference to the offending file using a text editor, then re-add the files in Xcode.

Solution 22 - Objective C

Note to self: "READ THE ERROR!"

In my case it says this: duplicate symbol _OBJC_CLASS_$_SATCoreData in:

Translation: an Objective C Class called SATCoreData is duplicated.

Then it gives the path to both occurrences of the symbol. Reading the path points to the two the class file ending in .o. If you look at both classes you will find something fishy. In my case I had accidently given two classes the same name. One class I had inside the file of another class because I was testing something and was too lazy to make a separate class. Hope this helps someone.

Solution 23 - Objective C

I had that problem and I was stuck for a while. The thing for me that caused the problem was I wrote some boolean into .h file (between #import and @interface) and use them into my .m file

I simply deleted them from my .h file and and copied them into the same place into my .m file and the build succeed.

Solution 24 - Objective C

Taken from https://stackoverflow.com/a/2755581/190599

What you can do is put in your header (MyConstants.h):

extern const int MyConstant;
extern NSString * const MyStringConstant;

And in a source file, include the header above but define the constants (MyConstants.m):

const int MyConstant = 123;
NSString * const MyStringConstant = @"SomeString";

Then, you simply need to include the header in any other source file that uses either of these constants. The header is simply declaring that these constants exist somewhere, so the compiler won't complain, because it's the linker's job to resolve these constant names. The source file that contains your constant definitions gets compiled, and the linker sees that this is where the constants are, and resolves all of the references found in the other source files.

The problem with declaring and defining a constant in a header (that is not declared as static) is that the compiler treats it as an independent global for each file that includes that header. When the linker tries to link all of your compiled sources together it encounters the global name as many times as you have included MyConstants.h.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBharatView Question on Stackoverflow
Solution 1 - Objective CRik Smith-UnnaView Answer on Stackoverflow
Solution 2 - Objective CDesparado_View Answer on Stackoverflow
Solution 3 - Objective CKyleTView Answer on Stackoverflow
Solution 4 - Objective CKalpesh PanchasaraView Answer on Stackoverflow
Solution 5 - Objective Creza23View Answer on Stackoverflow
Solution 6 - Objective CjimmybView Answer on Stackoverflow
Solution 7 - Objective CIman NiaView Answer on Stackoverflow
Solution 8 - Objective CJeff GrimesView Answer on Stackoverflow
Solution 9 - Objective CStorm FactoryView Answer on Stackoverflow
Solution 10 - Objective CMatt BeckerView Answer on Stackoverflow
Solution 11 - Objective Cuser3095716View Answer on Stackoverflow
Solution 12 - Objective CBharatView Answer on Stackoverflow
Solution 13 - Objective CAFTAB MUHAMMED KHANView Answer on Stackoverflow
Solution 14 - Objective CAronView Answer on Stackoverflow
Solution 15 - Objective CRob SandersView Answer on Stackoverflow
Solution 16 - Objective CAlvin GeorgeView Answer on Stackoverflow
Solution 17 - Objective CSanjeevView Answer on Stackoverflow
Solution 18 - Objective CEricView Answer on Stackoverflow
Solution 19 - Objective CYunus Nedim MehelView Answer on Stackoverflow
Solution 20 - Objective CSikanderView Answer on Stackoverflow
Solution 21 - Objective CSomaManView Answer on Stackoverflow
Solution 22 - Objective CsmileBotView Answer on Stackoverflow
Solution 23 - Objective CRed.AView Answer on Stackoverflow
Solution 24 - Objective CCodeReaperView Answer on Stackoverflow