2013-03-07 27 views
0

我在xcode项目中使用了一个cpp文件。在cpp文件我做了以下在cpp中声明的gloabal变量在目标c中使用

ReadYML.h

typedef struct { 
    float Position[3]; 
    float Color[4]; 
    float TexCoord[2]; 
} Vertex_OR; 

extern Vertex_OR Vertices_OR [100]; 

extern GLubyte Indices_OR [30]; 

在ReadYML.cpp

我赋值这一点。

在view.m

我宣布 “sample.h”

,并试图访问Vertices_OR和Indices_OR但我得到下面的错误?

Undefined symbols for architecture i386: 
    "_Indices_OR", referenced from: 
     loadyml() in ReadYMLfile.o 
    "_Vertices_OR", referenced from: 
     loadyml() in ReadYMLfile.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

这里有什么问题?我需要使用在“Sample.h”中声明的全局变量来访问view.m?可能吗?

+0

'出现view.m'未包含在此链接器错误中;而是它看起来像'ReadYMLFile.o'。 – trojanfoe 2013-03-07 16:22:09

回答

2
extern Vertex_OR Vertices_OR [100]; 

extern GLubyte Indices_OR [30]; 

extern表示 “嘿,编译器,这个符号存在地方”。如果你没有像一些编译单元某处下面相应的声明,你会得到链接错误(即把这个在相应.m文件的地方):

Vertex_OR Vertices_OR [100]; 

GLubyte Indices_OR [30]; 
+0

我拿了“我为此分配的值”。因为他已经正确地初始化了这些变量。 – trojanfoe 2013-03-07 16:28:18