-2

I'm currently trying to write a little game with OpenGL. I got 2 classes:

  • CoreEngine: for managing the Window, rendering, updating and so on
  • Mesh: for creating and managing meshes

Includes from CoreEngine.h:

#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <vector>

#include "RenderingEngine.h"
#include "GameObject.h"

Includes from Mesh.h:

#ifndef _MESH_H_
#define _MESH_H_
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include <string>

The reason is that I need functions from OpenGL in CoreEngine.h and in Mesh.h, but when I try to compile I get this error:

Fehler  1   error C1189: #error :  gl.h included before glew.h

I can't find a way, to prevent this error and to have OpenGL functions in both classes at the same time.

F. Baum
  • 301
  • 1
  • 5
  • 17

1 Answers1

0

Firstly, check if you have precompiled headers enabled (stdafx.h) - If you do, Don't. - In fiveteen years of software development I've only had one project that needed precompiled-headers. And even there it caused endless junior developers a headache.

Secondly, Check your individual CPP Files, it's possible you may find something such as

#include <gl/gl.h>
#include "mesh.h"

Finally As a first and last resort (for visual studio users) such as yourself you can display the list of all include statements, and the order they where included: using /show includes - See this question for details

You may very-well find that some other library includes gl.h at an earlier point in your program (such as a graphics import library, or even a mathematics library (such as glm). Using the import-graph for this problem is the reccomended approach.

Community
  • 1
  • 1
John Bargman
  • 1,267
  • 9
  • 19