user366584
user366584

Reputation: 1056

duplicate symbol _OBJC_METACLASS_$_ClassName

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

Upvotes: 44

Views: 39267

Answers (18)

arihant jain
arihant jain

Reputation: 115

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.

Upvotes: 0

Tonnie
Tonnie

Reputation: 169

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.

Upvotes: 5

BootMaker
BootMaker

Reputation: 1647

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

Upvotes: 26

Jibeex
Jibeex

Reputation: 5819

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

Upvotes: 16

Romain TAILLANDIER
Romain TAILLANDIER

Reputation: 1995

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.

Upvotes: 1

Atef
Atef

Reputation: 2902

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 :)

Upvotes: 0

Korbinian Breu
Korbinian Breu

Reputation: 211

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

Upvotes: 3

RileyE
RileyE

Reputation: 11084

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!

Upvotes: 6

Mayur Kothawade
Mayur Kothawade

Reputation: 544

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.

Upvotes: 0

stoiczek
stoiczek

Reputation: 1363

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.

Upvotes: 0

gmogames
gmogames

Reputation: 3081

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.

Upvotes: 0

derekv
derekv

Reputation: 3141

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.

Upvotes: 164

Tom Andersen
Tom Andersen

Reputation: 7200

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.

Upvotes: 3

Dan Power
Dan Power

Reputation: 1141

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.

Upvotes: 0

Egil Rausner
Egil Rausner

Reputation: 381

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.

Upvotes: 37

EmphaticArmPump
EmphaticArmPump

Reputation: 774

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.

Upvotes: 2

user366584
user366584

Reputation: 1056

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.

Upvotes: 1

JeremyP
JeremyP

Reputation: 86651

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

Upvotes: 55

Related Questions