Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

iphone - Xcode duplicate symbol error

I am getting "Apple Mach-O Linker (Id) Error":

ld: duplicate symbol _matrixIdentity in /BlahBlah/Corridor.o and /Blahblah/Drawable.o for architecture i386

The class "Corridor" is extending the class "Drawable" and "_matrixIdentity" is defined and implemented in a file "Utils.h". Here are top lines from my header files:

Drawable.h

#import <Foundation/Foundation.h>
#import "Utils.h" 
@interface Drawable : NSObject
...

Corridor.h

#import <Foundation/Foundation.h>
#import "Drawable.h"
@interface Corridor : Drawable
...

I have already checked if there are any ".m" imports instead of ".h", everything is correct. Any idea, what could cause this problem?

EDIT: posting code from "Utils.h"

#import <Foundation/Foundation.h>    
...
#pragma mark -
#pragma mark Definitions

typedef float mat4[16];

#pragma mark -
#pragma mark Functions
void matrixIdentity(mat4 m)

{
m[0] = m[5] = m[10] = m[15] = 1.0;
m[1] = m[2] = m[3] = m[4] = 0.0;
m[6] = m[7] = m[8] = m[9] = 0.0;
m[11] = m[12] = m[13] = m[14] = 0.0;
}
...

I am only referencing to "mat4" definition in my both classes' methods. Also, "matrixIdentity" is just the first function in this file, may be the problem is not in implementation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

C/C++/Objective-C diff with Java, C#, Ruby, Python...

Divide files.

header & mm

Do not use #include (may include many times)

Use #import... (include once)


Utils.h

#ifndef __utils_h__ // <<< avoid multiple #include
#define __utils_h__ // <<< avoid multiple #include
#import <Foundation/Foundation.h>    
...
#pragma mark -
#pragma mark Definitions

typedef float mat4[16];

#pragma mark -
#pragma mark Functions
extern void matrixIdentity(mat4 m);

#endif // __utils_h__ <<< avoid multiple #include

Utils.mm

#import "Utils.h"

void matrixIdentity(mat4 m)
{
m[0] = m[5] = m[10] = m[15] = 1.0;
m[1] = m[2] = m[3] = m[4] = 0.0;
m[6] = m[7] = m[8] = m[9] = 0.0;
m[11] = m[12] = m[13] = m[14] = 0.0;
}
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...