I have a header file that defines 2 arrays
//GeometricPrimitives.h
#ifndef GEOMETRIC_PRIMITIVES_H
#define GEOMETRIC_PRIMITIVES_H
#include <gl/glew.h>
GLfloat cubeVerts[] = {
//UP
0.5, 0.5, -0.5,
0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
-0.5, 0.5, -0.5,
//DOWN
0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, 0.5,
-0.5, -0.5, -0.5,
//LEFT
-0.5, 0.5, -0.5,
-0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
-0.5, -0.5, -0.5,
//RIGHT
0.5, 0.5, -0.5,
0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
0.5, -0.5, -0.5,
//FRONT
-0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, 0.5,
//BACK
-0.5, 0.5, -0.5,
0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
-0.5, -0.5, -0.5,
};
GLbyte cubeIndices[] = {
1,2,3, 3,4,1,
5,6,7, 7,8,5,
9,10,11, 11,12,9,
13,14,15, 15,16,13,
17,18,19, 19,20,17,
21,22,23, 23,24,21
};
#endif // !GEOMETRIC_PRIMITIVES_H
And file that includes it
//Mesh.h
#pragma once
#include <gl/glew.h>
#include <SDL_opengl.h>
#include <gl/GLU.h>
#include "ShaderProgram.h"
#include "GeometricPrimitives.h"
class Mesh
{
public:
Mesh();
void bind(ShaderProgram* program);
void init();
void render();
private:
GLuint vao;
GLuint vbo;
GLuint ibo;
GLfloat* vertices;
int verticesCount;
GLbyte* indices;
int indicesCount;
};
Mesh.h is included in GameObject.h which is included in main.cpp.
When i compile i get error Error LNK2005 "float * cubeVerts" (?cubeVerts@@3PAMA) already defined in GameObject.obj
I read that this comes from the issue that the file gets added multiple times in different obj-s and then those get merged together giving the multiple definitions. How can i create this header with these static values and use them where i need them ?