Xcode: I just got an Apple Mach-O Linker (Id) Error and don't know why - iphone

I'm new to iOS Development, I'm using the latest version of Xcode and just got an error that said Apple Mach-O Linker (Id) Error exit code 1 and I haven't got a clue why. I think this is relevant but I'm not sure what it means:
ld: duplicate symbol _OBJC_CLASS_$_Timing1ViewController in /Users/tomkenning/Library/Developer/Xcode/DerivedData/EggTimer-ciznfdheqrtybuavrtbbcxfywyyw/Build/Intermediates/EggTimer.build/Debug-iphonesimulator/EggTimer.build/Objects-normal/i386/Mediumhb.o and /Users/tomkenning/Library/Developer/Xcode/DerivedData/EggTimer-ciznfdheqrtybuavrtbbcxfywyyw/Build/Intermediates/EggTimer.build/Debug-iphonesimulator/EggTimer.build/Objects-normal/i386/Timing1ViewController.o for architecture i386
All I've done recently is initialise and set some integer values in a .m file and then link to them from .h file from another ViewController, using #import "suchandsuch.m", there's been no errors in the code, but is that not allowed?
Thanks in advance for any help you can offer!

Don't do this:
#import "suchandsuch.m"
Do this:
#import "suchandsuch.h"
You are probably compiling suchandsuch.m, which defines the class Timing1ViewController, normally (by including suchandsuch.m in your target's list of files to build). Then your #import "suchandsuch.m" causes that same code to be inserted into a different source file, which is compiled as well. The result: two different source files try to define Timing1ViewController.
To do your constants the right way -- by declaring them extern in suchandsuch.h and defining them in suchandsuch.m -- see this answer.

You probably have two Timing1ViewController classes with the same name. If you don't try to Product -> Clean and build again.

Related

1 duplicate symbol for architecture i386

I am facing a critical problem here, Xcode throws strange exception while building it's
"
duplicate symbol _selected in:
/Users/mhgaber/Library/Developer/Xcode/DerivedData/اProject-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassX.o
/Users/mhgaber/Library/Developer/Xcode/DerivedData/Project-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassY.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I searched a lot but I didn't find anything help me please
Look at both the files for ClassX and ClassY - What targets are they included in? Basically the _selected method is duplicated in both of them. I am going to guess this is a plain C method that happens to be named the same in both files. Try renaming _selected in one of the files.
In my case, I was declaring a const in a header file, which worked fine when building and running on the device (iPhone 5), however when attempting to simulate a 4S, all of a sudden I had some 300 "duplicate symbols".
It turns out I needed to also mark the const as static and the issue went away. Presumably it was trying to redefine the constant every time the header was referenced. The compiler isn't smart enough to just make constants static? Didn't think that would be necessary, but I guess it is.
const CGFloat kTitleAnimateDistance = 50.f;
Needed to be:
const static CGFloat kTitleAnimateDistance = 50.f;
Some time you accidentally importing the .m file instead of the .h due to which this error comes. Please check and If this is not the reason, then perform the following steps
1- Check Build phases in Target settings.
2- Go to compile source section.
3- Check if any file exists twice or once.
4- If file exist twice delete one.
5- Build again.
I was having the same problem and #dtrotzjr 's answer gave me a hint as to what could be causing it.
In my case I had a plain C void function in my framework (which xcode was complaining about as a duplicate symbol) and i needed to declare it as static void
I had the same issue. I was including a .h file with a number of const strings, methods and a struct. When I changed them all to static except the only mutable variable I wanted, it compiled just fine.

Duplicate Symbol Error for architecture i386

I got this error when i tried to build:
"duplicate symbol __Z8ERRCHECK11FMOD_RESULT in:
/Users/codemenmini2012-2/Library/Developer/Xcode/DerivedData/MagicSleepFullVersion-agxulkdijnxbqmbuigucmrczufyw/Build/Intermediates/MagicSleepFullVersion.build/Debug-iphonesimulator/MagicSleepFullVersion.build/Objects-normal/i386/MagicSleepViewController.o
/Users/codemenmini2012-2/Library/Developer/Xcode/DerivedData/MagicSleepFullVersion-agxulkdijnxbqmbuigucmrczufyw/Build/Intermediates/MagicSleepFullVersion.build/Debug-iphonesimulator/MagicSleepFullVersion.build/Objects-normal/i386/MagicSleepViewControllerIpad.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)"
How to solve this guys?
The error may occur when you copy and paste the contents of one file to another file with its interface name which means two classes with same interface name.
In your code you have two different files with the same Interface name.
For me this error happened because I was dumb enough to copy the whole folder of a downloaded lib to the project and there was a demo project inside it. So I had two main.m files. Hope this helps anyone!
In my case I had accidently imported .m file instead if .h file. Hope it helps someone for this kinda silly mistake.
when you create bool variables with same name in two different classes then this error comes.
"duplicate symbol __Z8ERRCHECK11FMOD_RESULT in"
so check your both classes
MagicSleepViewController.m and
MagicSleepViewControllerIpad.m.
for same bool variables.
Change the bool variable name, your problem will solve.
Looks like you have at least one (probably more) symbol (or methods, functions, etc.) that's duplicated between MagicSleepViewController.m and MagicSleepViewControllerIpad.m.
You need to either 1) change the names of one set of duplicated methods or 2) figure out a way to merge MagicSleepViewController.m & MagicSleepViewControllerIpad.m so the same code will work on both iPhones and iPads (e.g. using run time conditionals or whatever to determine what kind of device your code is currently running on).
I had #defines placed in two files that were exactly the same... DOH.
For me, a search in the finder for the named duplicates has helped.
The problem in my case was caused due to multiple references in the "Compile Sources". So I deleted one from Project->Build Phases-> Compile Sources.

Suppress warning: Meta method xx in category from xx conflicts with same method from another category

How can I suppress this compiler warning:
Meta method 'prefix' in category from '...soap+prefix.o' conflicts with same method from another category ?
here is the category soap+Prefix.h:
#interface Soap (Prefix)
+(NSString*)prefix;
#end
and soap+prefix.m:
#import "Soap.h"
#import "Soap+Prefix.h"
#implementation Soap (Prefix)
+(NSString*)prefix { return #"EInspector"; }
#end
and these two files by the way are automatically generated with SudZc wrapper for web services.
p.s. this warning is issued ONLY in XCode 4.4
thank you so much in advance.
This happened to me when I have accidentally imported an implementation file of a category (.m) instead a header file (.h).
Somewhere else in your project, +[Soap prefix] is being declared in a category. Try searching your project for other declarations of +prefix.
Another possibility is that during a large refactoring or complex merge of your project.pbxproj file, the project ended up with two references or copies of the same file, and both are being compiled. I've seen it happen, and these sorts of warnings or errors are usually what happens. Try searching in the Finder for other files with the same name to see if you have a duplicate file somewhere.
In my case the issue was due to a wrong merge of project.pbxproj (so similar to Nick Forge's case), which caused too many references to the same file (however the file was physically only once on disk). When I removed redundant references the warning stopped appearing.
You should reference a great answer by someone who also posted something similar:
Is there a way to suppress warnings in Xcode?
In my opinion the 2nd (highest voted) option is the best!

Cannot find interface declaration for 'UIResponder'

I am running into this issue when trying to compile code for an iPhone app that I inherited from a previous developer. I've poked around on a couple forums and it seems like the culprit may be a circular #import somewhere.
First - Is there any easy way to find if this is the case/find what files the loop is in?
Second - Its definitely possible this isn't the problem. This is the full error (truncated file paths so its easier to view here):
In file included
from [...]/Frameworks/UIKit.framework/Headers/UIView.h:9,
from [...]/Frameworks/UIKit.framework/Headers/UIActivityIndicatorView.h:8,
from [...]/Frameworks/UIKit.framework/Headers/UIKit.h:11,
from /Users/wbs/Documents/EINetIPhone/EINetIPhone_Prefix.pch:13:
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:15: error: expected ')' before 'UIResponder'
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:17: error: expected '{' before '-' token
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:42: warning: '#end' must appear in an #implementation context
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:51: error: expected ':' before ';' token
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:58: error: cannot find interface declaration for 'UIResponder'
As you can see, there are other errors alongside this one. These seem to be simple syntax errors, however, they appear in one of Apple's UIKit files (not my own) so I am seriously doubting that Apple's code is truly producing these errors.
I'm stumped as to how to solve this issue. If anyone has any ideas of things I could try or ways/places I could get more info on the problem, I'd really appreciate it. I'm very new to Obj-C and iPhone coding.
Edit:
Just tried Clean All Targets - it actually found an extra warning but still have the same errors as above.
My EINetIPhone_Prefix.pch:
//
// Prefix header for all source files of the 'EINetIPhone' target in the 'EINetIPhone' project
//
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
Edit #2:
Interestingly, I tried removing the UIKit import from my prefix file and putting it into the specific .m files that need it. I still get the same errors, but now they occur in every file attempting to import UIKit.h. Is it possible that UIKit is messed up?
Perform a “Clean” (under the “Build” menu) and make sure to check “Also Remove Precompiled Headers”.

Where is a good place to place Category in Obj-c?

I've addeda category to NSString. I've tried to place the code in my appDelegate.h and it works. However, I've tried placing it in another .h file that I included from .pch file so that this category can be used project wide. However I kept getting the following error:
ld: duplicate symbol .objc_category_name_NSString_StringTrim in ....AppDelegate.o and .....main.o
collect2: ld returned 1 exit status
The weird thing is, I only get this error when I compile for the simulator but not device! Any ideas?
I always declare categories in Foo+Category.h and Foo+Category.m, for example NSString+Hashing.h and NSString+Hashing.m. In the source that uses the category I then import the Foo+Category.h and everything works wonders. The good thing about this solution is that the category gets mentioned explicitly in the code that uses it, so that the magic is apparent.