How do I fix this duplicate symbol error? - iphone

From the error I am getting:
ld: duplicate symbol _main in /Users/wostler/Library/Developer/Xcode/DerivedData/UIPageViewControllerDemo-hjsgatcuhsxeokdnubifybpivzum/Build/Intermediates/UIPageViewControllerDemo.build/Debug-iphonesimulator/UIPageViewControllerDemo.build/Objects-normal/i386/fmdb.o and /Users/wostler/Library/Developer/Xcode/DerivedData/UIPageViewControllerDemo-hjsgatcuhsxeokdnubifybpivzum/Build/Intermediates/UIPageViewControllerDemo.build/Debug-iphonesimulator/UIPageViewControllerDemo.build/Objects-normal/i386/main.o for architecture i386
I can't figure out why this error is occurring. I simply changed some framework files in my project and now this error won't go away! It obviously says _main is being duplicated, but I dont know where, or why?
What is causing this?

You need to look at the main.m/.h and fmdb.m/.h files. What is most likely is that they are both importing something that defines _main, perhaps at a global level. Usually thats the sort of thing that generates this error for me.

You have two main function in your code. Do a global search for main and remove the one you don't want.
It happens when you add some other project's files to your project without remove the main function.

Sounds like you have multiple entries under Targets/Compiled Sources. Check and remove them.

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.

Undefined symbols for architecture i386

i am getting this error it si hard to explain thats why i am attaching the image
this error accure when i am adding I class Base64.h
Most likely, the file Base64.m is not properly added to your project. It doesn't get compiled so it's missing when the final image is being linked.
Make sure the file Base64.m is the same kind of project member as FirstViewController.m (similar location, similar settings etc.).
i found the solution it is amy just a trick but i create the both base64 h and m files again with different name and then use it that time it works
thank to you

Objective C: "_main", referenced from: Start in crt1.3.1.o error

Trying to compile a iPhone/iPad application with SDK3.2 and am getting this error:
Undefined symbols:
"_main", referenced from:
Start in crt1.10.5.o
Symbol(s) not found
Collect2: Id returned 1 exit status
I think it's telling me that it's somehow trying to work with code from another SDK but searching the web has not provided any clear answers.
Anyone able to guide me on this and what to look for?
It looks like you haven't provided a main function in any of your source files. The crt object file is most likely the startup code which sets up your environment then calls main (CRT usually stands for C runtime, when it's not being used to mean Cathode Ray Tube, which it shouldn't any more, that being dead technology and all).
The Undefined symbols: "_main" ... simply means that the linker has discovered crt1.10.5.o needs the _main symbol satisfied and none of the files provided are satisfying it.
Short of seeing the actual linker command line, we can't be certain what's being included. You should check your source code and confirm or deny the existence of main()? And that it's inluded in the build?
There appears to be several possible causes.
I ran into this problem when the Perform Single-Object Prelink build option was checked
(GENERATE_MASTER_OBJECT_FILE = YES).
I got this when I opened a Swift project in Xcode 5. When I opened it in Xcode 6, it worked fine.

Xcode 3.2.1 - Why are Core Data generated Classes resulting in Build errors?

It looks like the recent Xcode 3.2 has added some code generation niceties that (I think) were lacking pre-Snow Leopard.
I took the following steps:
Define a simple .xcdatamodel model with a few entities, including one (inversible) one:many relationship (an Endpoint has many Subscription objects)
File -> New and select the (icon-less) "Managed Object Class". From that wizard, I selected my classes and I was off to the races.
Until, that is, I tried to build. I get this result and can't figure out:
Undefined symbols:
"_OBJC_METACLASS_$_NSManagedObject", referenced from:
_OBJC_METACLASS_$_Subscription in Subscription-B5BE258DF28BC03B.o
_OBJC_METACLASS_$_Endpoint in Endpoint.o
"_OBJC_CLASS_$_NSManagedObject", referenced from:
_OBJC_CLASS_$_Subscription in Subscription-B5BE258DF28BC03B.o
_OBJC_CLASS_$_Endpoint in Endpoint.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
What I'd love help with:
If anyone has any ideas of what I just did wrong, that'd be fantastic.
It looks like the only way to get Xcode to *re-*generate your classes is to File -> New and replace them again, which (among other things) results in duplicate references to the new classes and your old class files uselessly left in a moved-aside folder in your project. Anyone know how to keep these in sync correctly? I haven't found any Apple documentation that covers the new stuff.
Did you add the CoreData.framework to your project (or accidentally remove it)? That might be the source of the linking error.
Also, I reccomend you check out MOGenerator, by Wolf Rentsch. It's a much
more powerful code generator for core data classes that uses the generation gap pattern. It can automatically regen classes every time you save the xcdatamodel while preserving your custom code.
The simplest (and most frequent, and most easy to overlook) way this happens is if you accidentally generate a new set of MOC classes without removing references to the old ones (maybe in a different group in your project or something). I just spent too long banging my head against XCode before I realised this was exactly what I'd done.