xcode 4.6.1 and LLVM 4.2: ld: 2 duplicate symbols for architecture armv7 - objective-c

My first attempt at building a company iOS library/framework was this week, by following the steps found at this blog post here.
For reasons beyond this question, I can only link when building for a Device and not for simulator.
However, now I am getting a very bizarre error:
ld: 2 duplicate symbols for architecture armv7 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
The lines in question suggest:
duplicate symbol _OBJC_CLASS_$_iContactsGridCell in:
/Users/*/Desktop/Projects/contactservice/branch/ContactServicesClient/DerivedData/iContacts/Build/Intermediates/iContacts.build/Debug-iphoneos/iContacts-5.1.build/Objects-normal/armv7/iContactsGridCell.o
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/athium-iOS.framework/athium-iOS
duplicate symbol _OBJC_METACLASS_$_iContactsGridCell in:
/Users/*/Desktop/Projects/contactservice/branch/ContactServicesClient/DerivedData/iContacts/Build/Intermediates/iContacts.build/Debug-iphoneos/iContacts-5.1.build/Objects-normal/armv7/iContactsGridCell.o
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/athium-iOS.framework/athium-iOS
Obviously the Class in question is iContactsGridCell.h
The class itself inherits from Cell.h
#interface iContactsGridCell : Cell
The class Cell.h is part of the framework, if I do not import the correct file, then as expected I get a semantic error: Cannot find interface declaration for Cell etc etc.
However, when I do import it, I get the following duplicate error.
This file is not included anywhere else in the project, apart from iContactsGridCell.h!
The file Cell.h in turn, is just a class found under the framework:
#interface Cell : NSObject
#property (strong,nonatomic) UIView *view;
#property CGRect rect;
#property int UID;
#property BOOL highlighted;
#property UIColor *b_colr;
- (id) initWithRect:(CGRect)frame;
- (BOOL) hasCoordinates:(CGPoint)coord;
- (void) ripple;
- (void) cubefy;
- (void) flipfy;
- (void) rotate;
- (void) setBg:(UIColor *)bg withAlpha:(CGFloat)alpha;
- (void) highlight;
- (void) unhighlight;
- (void) updateWithRect:(CGRect)rect;
#end
Why on earth am I getting the duplicate error?
What could be causing this?
How could it get fixed?
How can I get more info more verbose output of where the duplicates are found?
PS: I have followed the intructions found at the blog to the letter. Yet I cannot link for simulator (getting a wrong architecture error) so my guess that maybe something is broken in the framework and not the project itself. Could this be the reason for the duplicate errors?

There are several places where this error could be arising. I would do the following to start searching for the problem:
Search the project folder with finder and see if anywhere else the file "iContactsGridCell.h" exists. Or if any two files exist somewhere.
Make sure that you don't have two Objects that are of Class iContactsGridCell that share the same name for example:
iContactsGridCell *myObj;
iContactsGridCell *myObj;
Make sure your not doing anything like this: #import
"iContactsGridCell .m"
Or like this: #import "iContactsGridCell.h" #import "iContactsGridCell.h"
Make sure your not re-declaring a class (including ones that Apple has provided in their frameworks)
Main Point: That's all I can think of off the top of my head. But the thing to remember is that somewhere in your project resides two objects, class declarations etc. That are the same. And the compiler is complaining because of it.
Why the Compiler would complain (more info): While this information is really "unnecessary" it's good practice as a programmer to understand what's going on under the hood and will often help debug, so here's a little info on compilers:
Remember that a Compiler (while much more complex) is a program just like the ones that you create using it. One of the steps in most (if not all) compilers go through at one point or another reading code is creating "Symbols or Keys" for each variable, class, struct ect. So, at some point the compiler reached a line of code that "repeats / duplicates" somewhere else. So the "Key/Symbol" creation process done routine by the compiler fails.

Related

missing #end + expected identifier "{" errors in XCode 4.2 .h module

I can't get rid of two errors on my class module, even when I have simplified the code to the minimum expression:
#import <Foundation/Foundation.h>
#interface MyClass : NSObject
#end
Both errors are reported on the #interface line, and they are:
- missing #end
- expected identifier or '{'
Check the header files that are #imported on the same page, and verify that the headers have matching #interface/#end statements.
I had the same problem, and XCode reported that my .m file's #implementation had a missing #end statement, even when I pared it down to just:
#import "MasterViewController.h"
#import "MyBadHeaderFile.h"
#implementation MasterViewController
#end
In reality the bug was a missing #end from a #imported MyBadHeaderFile.h file.
I had a similar problem found adding a } in my code got rid of the errors for me.
Before I added the } I was getting the following errors:
unexpected # in program (parse issue)
Expected } (parse issue)
#end is missing in implementation context (semantic issue)
rokjarc's comment should be a correct answer:
1) compiler can point you to completely wrong file. go trough all .h and .m files in your project and check for matching '#interface'/'#end', '#implementation'/'#end' and so on.
2) it happens also if you by mistake import .m file instead of .h
It doesnt matter in which file the error is appearing. Make sure to check for all the files you have recently modified. I appeared to have copied a file from test project to my actual project and forgot #end in one of the files. It gave me error on totally unrelated .h file.
Try to remove the implementation file of this class from "Compile sources in project settings"
#interface MyClass : NSObject{
}
#end
I experienced a similar issue, the code was fine but it was throwing this error.
I eventually resolved it by cleaning the project, have you tried that?
PEBKAC + Lack of Specificity in the Static Analyzer Strings
The existing answers are certainly useful. I just want to add a common PEBKAC that causes this; as well as highlight that CLANG should be clearer here. Someone with domain knowledge should file a patch to make the error message clearer. The \n#end\n part of the message is ridiculous no matter what.
(Showing line breaks as \n in a message designed to help users of a
GUI? Really CLANG?)
The Cause
When you have just created a new Class, the #interface & #implementation files look extremely similar, and Xcode will automatically place your cursor in the implementation.
If you thoughtlessly begin typing out your interface (your method signature declarations) in the implementation file, you'll end up with this warning because the analyzer sees methods without opening and closing braces.
A visual example, shown forthwith
I had the same error ,and it was because i had
#interface MyViewController ()
declared two times in the MyViewController.m

Command /Developer/usr/bin/clang failed with exit code 1

I was trying to make a simple Mac Objective-C application with Xcode to keep score of two players playing a simple game with up to 36 scores per player. It isn't a very practical application because of its limited features, and it's mostly for practice. I was trying to expand the application a bit with a Preferences window, which would pop up when a menu item was clicked.
I created a file to control the men item, then a nib to pop up when it's clicked. All of this worked fine, and a new window would pop up. I put sliders, text fields, etc. on the nib, and connected them to actions. All of that worked fine.
The problem came when I tried to import the files into my root controller so that I could use the user's choices in the application.
I got the following compiler error:
Command /Developer/usr/bin/clang failed with exit code 1
Along with all of this:
Ld
"/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug/SimpleScoreKeeper
Mac.app/Contents/MacOS/SimpleScoreKeeper Mac" normal x86_64
cd "/Users/myusername/Dropbox/iphone
app/SimpleScoreKeeper Mac"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/clang -arch x86_64 -isysroot
/Developer/SDKs/MacOSX10.6.sdk
-L/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug
-F/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug
-filelist
"/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper
Mac.build/Debug/SimpleScoreKeeper
Mac.build/Objects-normal/x86_64/SimpleScoreKeeper Mac.LinkFileList"
-mmacosx-version-min=10.6 -framework Cocoa -o
"/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug/SimpleScoreKeeper
Mac.app/Contents/MacOS/SimpleScoreKeeper Mac"
ld: duplicate symbol _addScores in
/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper
Mac.build/Debug/SimpleScoreKeeper
Mac.build/Objects-normal/x86_64/Prefrences.o and
/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper
Mac.build/Debug/SimpleScoreKeeper
Mac.build/Objects-normal/x86_64/RootController.o for architecture
x86_64 clang: error: linker command failed with exit code 1 (use -v to
see invocation) Command /Developer/usr/bin/clang failed with exit code
1
The (possibly) related files in my project follow.
RootController.h - All the interface declarations for stuff in the MainMenu.xib window
RootController.m - Where I need to import the files to
MainMenu.xib - The nib owned by the RootController class
Preferences.h - A file I'd want to import, but it won't work.
Preferences.m - A file I'd (maybe) want to import, but it won't work.
Preferences.xib - The nib owned by the Preferences class.
PreferencesMenuController.h - Where I declare the clickPreferences action. (Liked to MainMenu.xib)
PreferencesMenuController.m - Where I say that clickPreferences opens up Preferences nib. (Linked to MainMenu.xib)
Is there a reason why I'd be getting this error? Is there something I need to do in the class I'm importing? Please be pretty detailed, I'm new to the language somight not know how to do certain things. And if there's anything I need to clarify, let me know.
EDIT:
Here's the code to the file I can't import.
#import "Preferences.h"
#implementation Preferences
int addScores;
- (IBAction)addScoresToggled
{
NSLog(#"addScores was toggled.");
}
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
}
#end
You can also get this error of you accidentally include the implementation file rather than the header file. e.g. #import "MyClass.m" instead of #import "MyClass.h"
This is the reason ld: duplicate symbol _addScore
In your project you have _addScore file more than one time. check your project hierarchy.
After receiving the exact same error, I noticed that I somehow had gotten two .h files with the same name in my project. Deleting the duplicate from the project's folder (not just removing the reference) solved the issue for me.
I ran into this issue just now because I had accidentally imported the .m file for a class instead of the .h file.
For anyone trying this answer: If the issue has appeared suddenly, have a think about what #import lines you added recently (or better yet, run a grep in git!).
select demo.xcodeproj,show the package content,delete the file named project.xcworkspace and the f xcuserdata
I recently came across this error. Are you importing the same .h file from two different files? This caused this error for me.
If you want the variable addScore to be accessable in multiple files, you need to define it in one .m file as:
int addScore;
and declare it in the associated .h file as:
extern int addScore;
If left out the "extern" keyword in the declaration, then the compiler sees that as a redefinition of addScore in every file the .h is imported/included into. That would lead to the error you are seeing.
I had the same problem after running two projects with the same application identifiers.
After removing (replace <yourlogin> with your account name):
project.xcworkspace/xcuserdata/<yourlogin>.xcuserdatad/UserInterfaceState.xcuserstate
it's started running under simulator but still not on the device, so I closed all opened projects, created a new one and copied files there, and finally it worked!
I was facing the same error when using RestKit. I selected RestKit target and cleaned/built it. then I selected my main target (my application) and cleaned/built it. that fixed it for me.
I meet this kind of error when I archive a project under Xcode 4.3 and 4.4,
and finally I ended up this error with switching from Standard(32/64-bit Intel) to 64-bitIntel
I had a different cause: using Xcode 4.4 the deployment target was set to 10.4 when the the minimum was 10.6. That solved for me.
I ran into this error when I accidentally clicked Product -> Test, instead of Product -> Run. I just cleaned the project by clicking Product -> Clean and the error was gone.
DUPLICATE or AMBIGUOUS header or implementation files
This can occur when there are multiple potential paths to the files you are importing.
For example if you import MyClass.h, but there are two instances of MyClass.h in your project
my solution:
I have been imported some .h and .m files in my project. but have not used it any of my classes.
so I removed those from finder. this caused the above error.
so I had to go the project setting/ build phases => then also remove those file references. they were in red color. because they have been deleted from finder not from Xcode

Strange error regarding instance variables & superclass

I've got some code where my classes inherit from a superclass, and everything has been working fine till now. I'm getting an error whenever I try to use any of the superclass variables, saying that they are undeclared (first use in this function). It's only happening in one of my subclasses, & it looks exactly the same as the others. I'm wondering if there's anything obvious which I should know about (being quite new to Objective-C). The basic code is like -
#interface mySuperClass : UIViewController {
BOOL myVar;
}
Then -
#interface mySubClass : mySuperClass {
}
#implementation mySubClass {
-(void)someMethod {
myVar = YES; // error here
}
#end
Any help much appreciated - if you need more info, let me know! Thanks.
I just got over a very similar strange error where I could no longer access properties in my superclass, and xcode was givine me compiler errors saying "(*) undeclared (first use in this function)". However I had not any problems in the past...
The problem was that I had introduced typos at the top of my .m file and the xcode compiler output was misleading me. Specifically I had #synthesize statements where the properties were misspelled, either in the synthesize statement or in the corresponding variable in the headerfile.
If you have #synthesize statements or other declarations, examine them with a fine toothed comb (i.e. which lines have you introduce most recently?), or even comment out a block of them to see if you can compile again and narrow down the culprit.
Again the compiler errors were very misleading, so it really was tough to debug. Although like 99.9% of the time the error was my own. :)
I can't see anything wrong with the code you've pasted. My first guess would be that you're not importing the mySuperClass .h file properly. Ie you're missing
#import "mySuperClass.h" //or #include
In mySubClass.h, or mySubClass.m
I ran into the same problem and after wasting hours I finally solved it in my project:
I refactored my source and removed a member but forgot to remove the #property definition in .h file. This leads to errors at every place when I am using super members. BTW: Methods from super are fine.
So check your property defs. Thanks to Screwtape in post 8 for his solution :-)
EDIT: Oops, Kris' answer is pretty similar except from typos vs. removal.
I am having the same issue for weeks
"Variable Undeclared" error when compiling to iOS Device, but not for Simulator
One solution I found is to simply change the compiler from the default LLVM GCC 4.2 to LLVM Compiler 2.0 (or to `Apple LLVM Compiler 2.1). It seems to be a bug in the compiler, but it is just a guess.
Changing it is a quick fix for your problem if there is no need for you to use the GCC compiler at all.

Xcode can't find headers in given framework

Messing round a little in Xcode, and I was trying to get my app to look at the users music library with the use of MPMediaPickerController.
Following Apples documentation, I added the MediaPlayer.framework to the project, and in my header I've imported , giving me something like this:
#import <GameKit/GameKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface HelloMusic : UIViewController
{
}
So far so simple. Now, as far as I'm aware I should be able to do
MPMediaPickerController *mp = [[MPMediaPickerController alloc] init];
in my main file and set about launching my picker. Unfortunately XCode stubbronly refuses to admit that there is such a thing as an MPMediaPickerController - if I type MP and hit escape to get code complations I am without any of the MPMedia family. Annoyingly Xcode does recognise any MPMovie... class (from the same framework!). If I try and run the app it compiles fine so it must at least recognise the header from the framework, then chunters along until I get to the assignment of MPMediaPickerController, at which point I get an EXC_BAD_ACCESS, with a console output of
Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
pthread_mutexattr_destroy$UNIX2003 called from function _ZN4llvm3sys5MutexC2Eb in image
libLLVMContainer.dylib.
I'm... certain I'm doing something beyond stupid, but I'm stuck nevertheless.
As the class reference states, it's declared in MPMediaPickerController.h. As such, simply adding...
#import <MediaPlayer/MPMediaPickerController.h>
...should solve your problems. :-)

Strange behavior with compile error "expected specifier-qualifier list before 'CustomClass'"

I have been having some trouble lately with using custom classes as types. As described in the title, I have been getting compile errors similar to the one below:
expected specifier-qualifier list before 'MyClass'
My code is usually something along the lines of this:
#interface MyCoolClass : NSObject {
MyClass *myClassObject; // Error is on this line.
}
I also occasionally use something like this:
#interface MyCoolClass : NSObject {
IBOutlet MyClass *myClassObject; // Error again on this line
}
Im not really sure if that is good to use but on occasion, I have done something like that so I could connect my objects together with Interface Builder so that one object could invoke a method on another object.
I've been able to do this before successfully with other projects but when I tried to do it today, it gave me this error. Any ideas what could be causing it? As far as I can tell, I have done the same thing that I did in the other project here.
It is also to my understanding that this error usually gets thrown if the type is not defined, but I am pretty sure that I have defined it.
Oh, GCC how obtuse and opaque can your errors possibly be....
Try compiling with the LLVM 2.0 compiler. It'll give you much more sane errors.
In this case, what is usually going on is that the compiler doesn't have a clue what MyClass is or there is a syntax error in the previously included header file that doesn't cause a compilation error until the #interface is hit in the file spewing the error.
It could also be a misspelling.
Or, as suggested, you need to #import "MyClass.h" into the header file (or implementation file or, even better, the PCH file) so that MyClass is defined before the iVar declaration.
#class MyClass;
That'll also do the trick.