【问题标题】:Linker Error Caused by Same Header Inclusion相同标头包含导致的链接器错误
【发布时间】:2014-05-20 16:50:58
【问题描述】:

我目前正在 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

【问题讨论】:

  • 发布链接器错误。
  • @Zaph 好的,我编辑它以添加链接器错误
  • 您能否将started_started 的定义发布在.h 中导入的Utilities.h 文件之一中?
  • 有一个重复符号:_started。它可能是一个名为started 的方法。搜索那个。

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


【解决方案1】:

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

【讨论】:

  • 可能在 Utilities.h 导入的四个标头之一中。
  • 你是对的,但也不对。它确实与名为started 的符号有关。但无论出于何种原因,这是一个我尚未删除的 BOOL 值,它在我的代码中设置为 false。你知道它为什么会这样做吗?
  • 显示代码??此外,当您收到错误消息时,确实要花时间尝试理解它们,当然链接器错误消息似乎更糟,但从中获取线索并不难。
  • 就像它实际上只是函数之外的全局 BOOL 变量。就像 BOOL 开始 = false;然后是一个函数。我把它放在全局只是为了对我正在做的事情进行简单的测试(回想起来我真的不知道为什么有必要在那里)
猜你喜欢
  • 2011-10-27
  • 2015-01-22
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
相关资源
最近更新 更多