Solved

OpenGL include file: multiple redefinitions of windows.h

Posted on 2004-10-28
365 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
Question by:DarkBlue
    2 Comments
     
    LVL 1

    Accepted Solution

    by:
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    The viewer will learn how to count occurrences of each item in an array.

    911 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now