我收到“Apple Mach-O 链接器 (Id) 错误”:
ld: duplicate symbol _matrixIdentity in /BlahBlah/Corridor.o and /Blahblah/Drawable.o for architecture i386
“Corridor”类扩展了“Drawable”类,“_matrixIdentity”在文件“Utils.h”中定义和实现。以下是我的头文件中最重要的几行:
可绘制.h
#import <Foundation/Foundation.h>
#import "Utils.h"
@interface Drawable : NSObject
...
走廊.h
#import <Foundation/Foundation.h>
#import "Drawable.h"
@interface Corridor : Drawable
...
我已经检查过是否有任何“.m”导入而不是“.h”,一切都是正确的。知道是什么导致了这个问题吗?
编辑:从“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”只是这个文件中的第一个函数,可能问题不在实现中。
最佳答案
C/C++/Objective-C 与 Java、C#、Ruby、Python 的区别...
分割文件。
标题和毫米
不要使用#include(可能包含多次)
使用#import...(包含一次)
实用程序.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
实用工具.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;
}
...
关于iphone - Xcode重复符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11773974/