Can't include <gl/gl.h>
Asked Answered
S

2

15

I'm using Visual Studio 2010. I'm trying to write simple Camera class in OpenGL. I need to include gl/gl.h in Camera.h
gl/gl.h is already included in main.cpp and Camera.h is included in main.cpp When I put

#include <gl/gl.h>

in Camera.h i got bunch of errors like this one:
Error 11 error C2086: 'int APIENTRY' : redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gl\GL.h 1153 1 Gaz 3D

files:
Camera.h

#include <math.h>
#include <gl/gl.h>

#ifndef _CAMERA_H
#define _CAMERA_H

class Camera
{
private:
    Camera();
public:
    static Camera& getCamera();
    float x, y, z, rotv, roth;
    void moveForward(float n);
    void moveBackward(float n);
    void moveLeft(float n);
    void moveRight(float n);
    void lookUp(float n);
    void lookDown(float n);
    void lookLeft(float n);
    void lookRight(float n);
};

#endif

main.cpp:

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <math.h>
#include "Camera.h"

// ... some variables ...

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,  
                   LPSTR lpCmdLine, int nCmdShow)
{
    // main code ...
}

What am I doing wrong?

Shockheaded answered 21/9, 2010 at 13:48 Comment(2)
I don't think that this is causing your problem, so I won't post it as an answer: #include <math.h> and #include <gl/gl.h> should be inside of the #ifndef guard in Camera.h. On second thought, you don't even need those includes in that header at all; you aren't using anything from them in the declaration of Camera.Cathcart
I'm not but I will be using math and gl.Shockheaded
E
27

Just do an include of windows.h first.

#include <windows.h>

As it's said in the OpenGL FAQ :

Also, note that you'll need to put an #include <windows.h> statement before the #include<GL/gl.h>. Microsoft requires system DLLs to use a specific calling convention that isn't the default calling convention for most Win32 C compilers, so they've annotated the OpenGL calls in gl.h with some macros that expand to nonstandard C syntax. This causes Microsoft's C compilers to use the system calling convention. One of the include files included by windows.h defines the macros.


Resources :

Efferent answered 21/9, 2010 at 13:52 Comment(0)
T
1

Edit: Obviously Colin Hebert solved the problem, but as a general tip I`d like to say:

In Camera.h write

#ifndef _CAMERA_H
#define _CAMERA_H

above all other includes. And include all header files needed in your .cpp file in your .h file.

At least that`s what I think is best practice.

Teliospore answered 21/9, 2010 at 13:56 Comment(4)
This should make no differences. The GL headers have an inclusion guard as well.Hak
That was rather meant as a general tip.Teliospore
if it wasn't meant to solve the user's problem, you should say so. As it is, it sounds like you're answering his question, and the answer is wrong.Bandwidth
@Bandwidth okay, sorry, did as you told me.Teliospore

© 2022 - 2024 — McMap. All rights reserved.