44

I am trying to run my cocos2d application and facing this error, as I have recently upgraded my sdk to 4.2 and my cocos2d to 0.99.5.

I tried to clean my project even change the Target ios Deployment but error remains the same. Also rename the className aswell in order to avoid duplication from Library classes names of cocos2d.

ld: duplicate symbol _OBJC_METACLASS_$_MenuSceneNew in /Users/umaidsaleem/Desktop/functionalityTest/build/Debug-iphonesimulator/libcocos2d libraries.a(MenuScene.o) and /Users/umaidsaleem/Desktop/functionalityTest/build/functionalityTest.build/Debug-iphonesimulator/functionalityTest.build/Objects-normal/i386/MenuScene.o

Ivan Mir
  • 1,209
  • 1
  • 12
  • 32
user366584
  • 1,016
  • 1
  • 16
  • 34

18 Answers18

164

Another rather simple thing to check is that you did not accidentally #import a .m file instead of a .h header file.

Happened to me.

derekv
  • 3,131
  • 3
  • 21
  • 30
55

You are linking the file MenuScene.m twice. You apparently have it in a static library and also in your main application.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • 1
    I even changed the name previously aswell to MenuSceneNew and whole class name has been changed to MenuSceneNew.h, MenuSceneNew.m but error remains the same. – user366584 Mar 18 '11 at 07:07
  • @user366584: It doesn't matter that you rename the class or the file, the fact is, it is being linked twice. – JeremyP Mar 18 '11 at 10:16
  • I have this problem. So what do you do if your static library depends on that file, which is also in another static library which your main application links against? – NYC Tech Engineer Jul 16 '15 at 17:17
  • @NYCTechEngineer Static libraries can depend on other static libraries. I'm not sure how it works in Xcode (I code for OS X where you can put everything in dynamic frameworks) but in normal C you have to make sure the static libraries are linked in the correct order. If `liba` makes a call to a function in `libb`, you need to make sure `libb` appears in the linker command line **after** `liba`. – JeremyP Jul 21 '15 at 09:29
37

Another reason for this, for those out there who did the same as I just did, might be that you re-created a managed object class. By doing that and choosing another group in the project structure, you accidentally create another reference to the same files.

I ended up with two references for header and implementation in both the root of the project and in my model group. Removing the topmost references to .h and .m files got rid of the linking failure.

Egil Rausner
  • 381
  • 3
  • 3
  • Thank you! I didn't event notice that. What a horrible waste of time. Thanks again for the tip. – technophobia May 29 '13 at 15:54
  • Thanks! This was my problem. Sure enough, I actually had header & impl 2x in the same Models folder! I've had it happen before but reading this pushed me to look closer. **facepalm** – dooleyo Jul 25 '13 at 15:24
  • Just bumped into this issue and the problem was that I created my entities in a group called 'x' then recreated in group 'y'... for some reason the silly pbxprojec file keeps the reference to everything and my build was failing. – rodrigoelp Aug 04 '14 at 05:42
  • Was my problem (again). I suppose there is a reason why a source file might be included in a build target more than once but it would be nice to have a warning on that from Xcode. They warn us for unused variables incessantly so why not overused source ;-) TMS error... too much source – Cerniuk Mar 14 '16 at 15:01
26

Sometimes Core Data inserts AnyProjectNameModel.xcdatamodeld to the Compile Sources of the Build Phases. Check it and delete it and everything is run again... The error message just indicates the generated ManagedObjects... The correct place for the AnyProjectNameModel.xcdatamodeld is the Copy Bundle resources in the Build Phases. enter image description here

BootMaker
  • 1,639
  • 1
  • 22
  • 24
16

Check the Compile Sources of your target and see if a class.m file is included twice

Jibeex
  • 5,509
  • 3
  • 27
  • 37
6

A stupid mistake that I made was that I named my @implementation the same as my superclass.

In the .h

@interface Subclass : Superclass
@end

In the .m

#import "Subclass.h"

@implementation Superclass
@end

None of the regular suggestions from google seemed to help, so if someone is as crazy or tired as I am (maybe a healthy mix of both), make sure you haven't duplicated an @implementation!

RileyE
  • 10,874
  • 13
  • 63
  • 106
5

In my case this was happening because of Xcode automatically generating my NSManagedObject class, which then clashed with my manually created NSManagedObject class. In this case you can set "Codegen" to "Manual/None" in the Data Model Inspector for your newly created Entity.

Tonnie
  • 149
  • 2
  • 8
3

Another thing to check for the double linking - its possible to have the same file in two different places in the file list on the left. Then the compiler compiles and links it twice.

This happens when playing with organizing your file hierarchy, for example.

You don't have to be making a library or anything fancy - just drag a .m in to two different locations in the project tree.

Remember to only remove the reference to one of them, no file trashing is needed.

Tom Andersen
  • 7,132
  • 3
  • 38
  • 55
3

To me, removing -all_load from 'Other Linker Flags' fixed the problem.

Korbinian Breu
  • 211
  • 2
  • 7
2

I have also had this particular error occur when a file that has not been added to the project, is referenced somewhere in the project. The two cases where I have experienced this are where I have deleted/removed files from the project without removing references to them, and when working cooperatively on a project where a teammate added the reference but I have not added the file to my version of the project.

I know the OP has resolved their problem, but I felt this might help someone else who reads this question while looking for help.

EmphaticArmPump
  • 774
  • 4
  • 7
  • 23
1

I had a project with 2 targets. A target named Component and the second named Sample. Sample was using component as a link library. Then Component was using a pod named MyPod (installed with cocoapod).

The Podfile was written like this :

def shared_pods
   pod 'MyPod' 
end

target 'Component' do
    shared_pods  
end

target 'Sample' do
    shared_pods
end

Both targets was referencing the shared pod list. When building Component target, no problem appears, but when building sample i get a duplicate symbol _OBJC_METACLASS_$_ClassName. I have changed the Podfile to :

def shared_pods
    # empty
end

target 'Component' do
   pod 'MyPod'
   shared_pods  
end

target 'Sample' do
    shared_pods
end

And that solve the problem. 3 hours spent, hope to save somebody time.

Romain TAILLANDIER
  • 1,765
  • 10
  • 18
1

I have figured out the solution myself, sorry for posting little delayed. All assistance are much appreciated the but problem arises when I add new CCLayer derived class and checkmark cocos2d 0.99.5 static library which was wrong. Then I re-Ad my class without checking and clean my targets and then build and go. Problem solved now.

user366584
  • 1,016
  • 1
  • 16
  • 34
0

XCode Beta crashed for me while deleting a reference to a class. This caused the problem described in the answer, the fix was different again.

In my Target's Build Phase, under "Compile Sources", the item giving me grief was red. I couldn't remove it with the minus button, but typing "skip" in the compiler flags caused the red class to disappear after reloading the project. I'm assuming you could type anything in there.

It took me two hours to find the solution to my prob, I put it in here for another option to those having this problem, although it is probably not going to be a common one.

Dan Power
  • 1,141
  • 1
  • 12
  • 18
0

None of the Answers worked for me, so what I did was remove the files from the project and choose only Remove References.

Then I added back the same files and it worked.

That fixed my error. Maybe XCode got lost references stored somewhere since the project is multi-collaboration.

Hope that helps someone.

gmogames
  • 2,993
  • 1
  • 28
  • 40
  • This worked for me too. During the commit, I looked at the changes in the .pbxproj file and found that, in the broken version, in the PBXSourcesBuildPhase section, in the array of files, the problem file was listed twice. This happened after the file was renamed, commit, push, and then pulled by a co-worker. It is apparently a bug in Xcode/git. I'd renamed or added a bunch of files; only this one got screwed up for some reason. – Jerry Krinock Jun 01 '15 at 22:35
0

Another possibility for error like this is when there is a class name collision. Either 2 classes with the same name within your project, or class from your project clashing with one defined in some of dependency libraries.

stoiczek
  • 1,333
  • 1
  • 8
  • 8
0

Remove target from right panel and again add target. This will remove any duplicate references. It may happen if 2 programmer add the same target and commit the project file.

Mayur Kothawade
  • 544
  • 4
  • 14
0

In my case I was using a binary library includes the same class name I was using outside, So I changed my class name and It's working fine :)

Atef
  • 2,872
  • 1
  • 36
  • 32
0

In my case, I had added the libxxxx.a to Link Binary with Libraries section in the subProjects as well as in the mainProject. Hence there were duplicate symbols. Removing from subProjects fixed it.

arihant jain
  • 115
  • 1
  • 8