I got two classes, which implementation contains an array named “geometryCoords”, in “Corridor” class it is initialized in declaration, and in “RhombusArray” it is done in the “init” method:
GLfloat _geometryCoords[]={/*Values here*/};
GLfloat _geometryCoords[];
...//In the init method
_geometryCoords = (GLfloat*)malloc(somevalue);
for(...){/*Assignment*/}
While debugging this method i noticed that “geometryCoords” has the values of the first class’ array before the initialization code is passed. After changing the declaration of array in “RhombusArray” from:
GLfloat _geometryCoords[];
to
GLfloat* _geometryCoords;
i got an “Apple Mach-o linker error: duplicate symbol _geometryCoords in /BlaBla/Corridor.o and /BlaBla/RhombusArray.o”.
Both of those classes’ headers are imported to the .mm file and removing one of them solves the conflict.
How should i handle this problem?
Both of these arrays must have global scope (i.e. they are declared outside of a function and outside of a class interface) for you to get the linker error and the other issue. Declare them like this:
The
statickeyword makes the symbol visible only within the compilation unit (the.mfile) in which they are declared.