duplicate symbols for architectures in Xcode

Although the following is not the cause in the OP's case, it was mine, so I'll share it here for anyone facing the same error:

If you are getting a linker error on all global variables, you might need to add extern to their declarations in your header files.

Whether the lack of extern will generate this issue is dependent on build settings, more specifically on "No Common Blocks" under "Apple LLVM - Code Generation" (GCC_NO_COMMON_BLOCKS, -fno-common). If set to yes, which is the default in newer versions of Xcode, you'll get a linker error without extern.

Why extern?

The extern keywords makes it a declaration only (i.e. not also a definition), which since it's a header file is what you want. Some compilers allow it without extern and still 'do the right thing', but omitting extern is discouraged. Which is why newer versions of Xcode by default enable the warning.


Here is a situation in Xcode 7.0 with duplicate symbols error, in case anyone else comes across this scenario

.h file

NSUserDefaults *defaults; // <----placing this above the @interface caused the issue

@interface someViewController

//...

Change to

.h file

@interface someViewController

{
   NSUserDefaults *defaults;
}

//...

In your build phases, check to see that you aren't compiling the same file more than once. i.e. If you search for main.m it should only return one result.

If that's not the problem, can you add the code from your main.m to the question?


Check your import files, it may that you're importing a .m file.

#import "TimeModel.m"