Xcode重复符号错误 [英] Xcode duplicate symbol error

查看:85
本文介绍了Xcode重复符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到Apple Mach-O Linker(Id)错误:

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

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

走廊课程正在扩展Drawable和_matrixIdentity类在文件Utils.h中定义和实现。以下是我的标题文件的第一行:

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

Drawable.h

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

Corridor.h

Corridor.h

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

我已经检查过是否有.m导入而不是.h,一切都是正确的。有什么想法,可能会导致这个问题吗?

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

编辑:从Utils.h发布代码

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;
}
...

我只引用mat4定义在我的两个班级的方法。另外,matrixIdentity只是这个文件中的第一个函数,可能是问题没有在实现中。

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.

推荐答案

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

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

划分文件。

标题& mm

header & mm

不要使用#include(可能包括很多次)

Do not use #include (may include many times)

使用#import ...(包括一次)

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


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;
}
...

这篇关于Xcode重复符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆