开发者

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 as开发者_StackOverflow社区well 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


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.


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


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.


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.

duplicate symbol _OBJC_METACLASS_$_ClassName


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


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!


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.


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.


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


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.


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.


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.


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.


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.


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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜