Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OpenGL include file: multiple redefinitions of windows.h

Posted on 2004-10-28
4
Medium Priority
?
383 Views
Last Modified: 2013-12-21
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.
0
Comment
Question by:DarkBlue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Accepted Solution

by:
CBueche earned 1000 total points
ID: 12589125
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
 

Assisted Solution

by:kvozi
kvozi earned 1000 total points
ID: 12638510
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question