开发者

Can't include <gl/gl.h>

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?开发者_JAVA技巧


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 :

  • social.msdn.microsoft.com - OpenGL problems
  • OpenGL FAQ - Why am I getting compile, link, and runtime errors?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜