问题描述
我正在使用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.cppWhen 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 :
另外,请注意,您需要在之前加上
。 Microsoft要求系统DLL使用特定的调用约定,该约定不是大多数Win32 C编译器的默认调用约定,因此他们在gl.h中注释了OpenGL调用,其中一些宏扩展为非标准C语法。这导致Microsoft的C编译器使用系统调用约定。其中一个包含在windows.h中的包含文件定义了宏。 #include< windows.h>
语句#包括< GL / gl.h>
资源:
- social.msdn.microsoft.com - OpenGL problems
- OpenGL FAQ - Why am I getting compile, link, and runtime errors?
这篇关于不能包含< gl / gl.h>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!