不能包含< gl / gl.h> [英] Can't include <gl/gl.h>

查看:1676
本文介绍了不能包含< gl / gl.h>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010.
我正在尝试在OpenGL中编写简单的Camera类。
我需要在Camera.h中包含gl / gl.h

gl / gl.h已经包含在main.cpp中了,Camera.h包含在main.cpp
中当我把

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>

在Camera.hi中出现了类似这样的错误:

错误11错误C2086:'int APIENTRY':重新定义C:\Program Files(x86)\ Microsoft SDKs \ Windows \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 3D

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

文件:

Camera.h

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 ...
}

我做错了什么?

推荐答案

首先要包含一个windows.h。

Just do an include of windows.h first.

#include <windows.h>

正如在OpenGL FAQ中所说的那样:

As it's said in the OpenGL FAQ :

另外,请注意,您需要在之前加上 #include< windows.h> 语句#包括< GL / gl.h> 。 Microsoft要求系统DLL使用特定的调用约定,该约定不是大多数Win32 C编译器的默认调用约定,因此他们在gl.h中注释了OpenGL调用,其中一些宏扩展为非标准C语法。这导致Microsoft的C编译器使用系统调用约定。其中一个包含在windows.h中的包含文件定义了宏。

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.






资源:

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

这篇关于不能包含&lt; gl / gl.h&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆