56

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.

Bharat
  • 2,987
  • 2
  • 32
  • 48
  • That is two separate errors - have you got a directory - /Users/somefolder/Documents/Bharat/MyApp copy/GoogleAdMobAdsSDK – mmmmmm Sep 05 '12 at 10:44
  • @Mark i've added AdMob library. – Bharat Sep 05 '12 at 10:49
  • the error says you have not - what does `ls /Users/somefolder/Documents/Bharat/MyApp\ copy/GoogleAdMobAdsSDK` show – mmmmmm Sep 05 '12 at 10:50
  • Read this, it might also help: http://stackoverflow.com/questions/3731470/duplicate-symbol-from-single-library-in-ios4-1-sdk – Resh32 Sep 05 '12 at 11:24

24 Answers24

234

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

Rik Smith-Unna
  • 3,465
  • 2
  • 21
  • 21
  • Wow. Xcode really needs to warn us about this! TIP: Search for .m" to quickly find where you've accidentally imported the wrong file! – jt_uk Mar 25 '14 at 00:31
57

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.
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
Desparado_
  • 605
  • 6
  • 7
25

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;
KyleT
  • 855
  • 1
  • 12
  • 18
  • And i accidentally declare and initialized same const in 2 files – Arfan Mirza Dec 08 '14 at 19:41
  • 1
    yes this can cause the error. You can also change to static NSInteger const ABCMyConstant = 6; and keep everything in the header file – Jeff Ames May 19 '15 at 09:04
  • Is there no way to declare constants in a header alone? Seriously, I'm lazy and I don't want to have to do this twice. No other reason. I'd prefer not to `#define` them. – devios1 Jun 04 '15 at 00:11
20

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

Kalpesh Panchasara
  • 1,730
  • 2
  • 15
  • 27
  • Hey its working but i am wonder how it works. You saved my day Kalpesh, please let me know how it works. Thanks again. – Prabhunath Reddy R S Jul 05 '17 at 10:16
  • @PrabhunathReddyRS - If you have two different class and wants to create same objectname for each class say NSString * strUserName. Then without setting NCB to No, you can't. Once you set NCB to YES then you OS will allow to use same object name for multiple objects. – Kalpesh Panchasara Aug 07 '17 at 11:09
11

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.

reza23
  • 3,079
  • 2
  • 27
  • 42
8

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...

jimmyb
  • 256
  • 3
  • 4
6

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

Iman Nia
  • 2,255
  • 2
  • 15
  • 35
4

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.

Jeff Grimes
  • 2,300
  • 1
  • 23
  • 23
4

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.

Storm Factory
  • 388
  • 2
  • 10
3

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.

Matt Becker
  • 2,338
  • 1
  • 28
  • 36
3

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.

2

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
  4. clean and rebuild
Bharat
  • 2,987
  • 2
  • 32
  • 48
2

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.

Aron
  • 3,419
  • 3
  • 30
  • 42
1

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

Rob Sanders
  • 5,197
  • 3
  • 31
  • 58
1

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.

AFTAB MUHAMMED KHAN
  • 2,189
  • 3
  • 18
  • 24
1

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.

Alvin George
  • 14,148
  • 92
  • 64
0

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...

Sanjeev
  • 39
  • 5
0

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

Eric
  • 446
  • 8
  • 11
0

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.

Yunus Nedim Mehel
  • 12,089
  • 4
  • 50
  • 56
0

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.

Sikander
  • 447
  • 4
  • 26
0

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.

SomaMan
  • 4,127
  • 1
  • 34
  • 45
0

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.

SmileBot
  • 19,393
  • 7
  • 65
  • 62
0

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.

Johan
  • 74,508
  • 24
  • 191
  • 319
Red.A
  • 1
0

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.

Community
  • 1
  • 1
CodeReaper
  • 5,988
  • 3
  • 35
  • 56