由相同的头部包含引起的链接器错误

时间:2014-05-20 16:50:59

标签: objective-c xcode macos clang linker-errors

我目前正在使用Xcode for Mac开发应用程序。我通常在找到如何解决问题时非常体面,但是一个错误总会让我感到困惑。当我在两个单独的类中包含相同的标头时,我得到重复的符号错误。我的代码看起来像这样:
Utilities.h

#ifndef __UTILITIES_H
#define __UTILITIES_H

#import <Foundation/Foundation.h>

#import "Path.h"
#import "Matrix.h"
#import "Shader.h"
#import "Texture.h"

#endif

BlaineEntity.h

#import "Utilities.h"

@interface BlaineEntity : NSObject
{
    GLuint blaineID[3];
    GLfloat modelMat[16], rotMat[16], transMat[16];
    GLuint blaineVID[1];
    GLuint textureID;
    GLint uniform_mytexture;

    Matrix *matrix;
    Texture *tex;
}

- (void)render;
- (void)update;
- (void)setup;
- (void)setLocation:(GLfloat)x y:(GLfloat)y z:(GLfloat)z Rotx:(GLfloat)rx Roty:(GLfloat)ry Rotz:(GLfloat)rz;
- (void)translate:(GLfloat)forward lr:(GLfloat)lr ud:(GLfloat)ud;

@end

TempEntity.h

#import "Utilities.h"

@interface TempEntity : NSObject
{
    GLuint tempID[3];
    GLfloat modelMat[16], rotMat[16], transMat[16];
    GLuint tempVID[1];
    GLuint texID;
    GLint uniform;

    Matrix *matrix;
    Texture *tex;
}

- (void)Render;
- (void)Update;
- (void)Setup;
- (void)SetLocation:(GLfloat)x y:(GLfloat)y z:(GLfloat)z Rotx:(GLfloat)rx Roty:(GLfloat)ry Rotz:(GLfloat)rz;
- (void)Translate:(GLfloat)forward lr:(GLfloat)lr ud:(GLfloat)ud;

@end

我该怎么做才能避免链接器错误...

修改
这是链接器错误

duplicate symbol _started in:
/Users/sonardev/Library/Developer/Xcode/DerivedData/Blaine's_Adventures:_The_Lost_Mark-eyovjgtlqhbbcoeukwivyitbhqly/Build/Intermediates/Blaine's Adventures: The Lost Mark.build/Debug/Blaine's Adventures: The Lost Mark.build/Objects-normal/x86_64/TempEntity.o
/Users/sonardev/Library/Developer/Xcode/DerivedData/Blaine's_Adventures:_The_Lost_Mark-eyovjgtlqhbbcoeukwivyitbhqly/Build/Intermediates/Blaine's Adventures: The Lost Mark.build/Debug/Blaine's Adventures: The Lost Mark.build/Objects-normal/x86_64/BlaineEntity.o
ld: 1 duplicate symbol for architecture x86_64

1 个答案:

答案 0 :(得分:1)

Utilities.h中包含的标题之一包含符号_started(可能是函数)。因此,_started间接包含在具有类实现的2个文件中,这会导致链接器错误。检查包含在Utilities.h项目中的项目内的所有标题。