2013-03-07 67 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