Duplicate Symbol link Error reason summary and solution [go]

Source: Internet
Author: User

from:http://www.cocoachina.com/bbs/read.php?tid=177492

Duplicate symbol is a common link error, and does not directly locate the problem as a compilation error. But after a period of summing up, it is found that there are always some rules to find this error.
For example, we have the following simplest two class code:

ClassA.h
#import <Foundation/Foundation.h>
@interface Classa:nsobject
@end


classa.m
#import "ClassA.h"
@implementation ClassA
@end


ClassB.h
#import <Foundation/Foundation.h>
@interface Classb:nsobject
@end


Classb.m
#import "ClassB.h"


@implementation ClassB
@end


The error message that appears after compiling is as follows:

Duplicate symbol _objc_metaclass_$_classa in:
/users/dajie/library/developer/xcode/deriveddata/linktest-cpjaaatiyqpvxcbzfzpklcbqrgqg/build/intermediates/ linktest.build/debug-iphonesimulator/linktest.build/objects-normal/i386/classa.o
/users/dajie/library/developer/xcode/deriveddata/linktest-cpjaaatiyqpvxcbzfzpklcbqrgqg/build/intermediates/ linktest.build/debug-iphonesimulator/linktest.build/objects-normal/i386/classb.o
Duplicate symbol _objc_class_$_classa in:/users/dajie/library/developer/xcode/deriveddata/ linktest-cpjaaatiyqpvxcbzfzpklcbqrgqg/build/intermediates/linktest.build/debug-iphonesimulator/linktest.build/ objects-normal/i386/classa.o
/users/dajie/library/developer/xcode/deriveddata/linktest-cpjaaatiyqpvxcbzfzpklcbqrgqg/build/intermediates/ Linktest.build/debug-iphonesimulator/linktest.build/objects-normal/i386/classb.old:2
Duplicate symbols for architecture I386clang:
Error:linker command failed with exit code 1 (use-v to see invocation)



From where the problem is, we should be able to extrapolate that there is a problem with this class of ClassA. If this class is written by ourselves, it is easy to do something.
You can consider the following reasons:
1. When the header file is introduced, the. m file is inadvertently introduced by mistake. This is usually a matter of examining the source files of the class that is having the problem.
Example: CLASSB.M file modified to the following

#import "Classb.h>"
#import "CLASSA.M"//This sentence has a problem
@implementation ClassB
@end



2. The same class, implemented two times, is two @implementation. This generally has a warning and is easier to spot.
Example: The CLASSB.M file is modified to the following:

Classb.m
#import "ClassB.h"
@implementation ClassB
@end
@implementation ClassA
@end



3. Engineering documents, the same class file was introduced two times, the cause of this error is probably two: first, multiple people collaborative development, resulting in project file merge conflict, second, the same name file is not in the same directory, added to the project caused by repeated additions. This is usually found in the file view, which is checked with the name filter.
4. In the targets build phase setting, check the Complie sources to see if the class that has the problem is duplicated, and filtering with filenames is easier to find. This problem is often caused by project file conflicts when collaborating with multiple developers. If you find this problem, just delete it. However, as I resolve the problem, when I delete one of the files, the duplicate files are automatically deleted, so you need to add them separately.
5. This problem can occur if a third-party library is referenced in our project, and there is a classa in the third-party library. If you can't modify the library code of a third party, you can only modify the code I believe in.


Welcome to Add.

Duplicate Symbol link Error reason summary and solution [go]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.