OpenGL include file: multiple redefinitions of windows.h

Hello all,

I am trying to write an OpenGL application. I have different classes that need to use gl.h. Obviously windows.h has to be included before gl.h and that's causing me problems. This is what I have:

File 1:
#include <windows.h>
#include "GL/gl.h"
#include "GL/glu.h"
class A {
Render(); //in here I use gl stuff
}

File 2:
#include <windows.h>
#include "GL/gl.h"
#include "GL/glu.h"
class B {
Render(); //in here I use gl stuff
}

When compiling this I get the error message that MFC appc cannot use #include <windows.h>. I have a Win32 application by the way.
I have already tried #ifdef's and don't seem to work. Is there any way to get around this problem? Without rewriting all my classes if possible. I know that if I have one file that has all the gl stuff it will work but that will make everything a mess since I have over 15 files. Basically each file has an object of some kind that has it's own rendering function. The main rendering function calls the render function from each object.

Thanks.
DarkBlueAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CBuecheConnect With a Mentor Commented:
By having tried ifdef's, do mean you've tried the following:

---------------------
file: MyCommon.h
---------------------
#ifndef MY_COMMON_H
#define MY_COMMON_H

#include <windows.h>
#include "GL/gl.h"
#include "GL/glu.h"

#endif // MY_COMMON_H

---------------------
file: classA.cpp
---------------------
#include "MyCommon.h"
class A {
Render(); //in here I use gl stuff
}

---------------------
file: classB.cpp
---------------------
#include "MyCommon.h"
class B {
Render(); //in here I use gl stuff
}

If you only have 15 files, do the rewrite.  I don't know your specific situation, but in the grand scheme of things that's usually a very small number of files to have to touch.
0
 
kvoziConnect With a Mentor Commented:
You can use:

#pragma once
#include <windows.h>
#include "GL/gl.h"
#include "GL/glu.h"

in two files before the includes, #pragma once mean to include file only once in entire project
0
All Courses

From novice to tech pro — start learning today.