Error while trying to use OpenGL

2019-08-05 05:36发布

问题:

I have a very simple C code in which I am trying to use OpenGl. When I include the following files

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>

I get the following error(and many more but they are similar): C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\GL/gl.h(1152) : error C2144: syntax error : 'void' should be preceded by ';'

but when I include

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>

I get the following error \mainfile.cpp(4) : fatal error C1083: Cannot open include file: 'GL/glut.h': No such file or directory

any idea what is happening?

I am using XP, VS2005

回答1:

GLUT isn't part of OpenGL. You need to install it, which is what that error says.



回答2:

Per this other answer you do need windows.h first.

On my SDK (v7.0a) there is no glut.h, just gl.h and glu.h.

 Directory of C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl


04/26/2011  05:00 PM    <DIR>          .
04/26/2011  05:00 PM    <DIR>          ..
09/30/2009  08:27 PM            69,085 GL.h
09/30/2009  08:27 PM            18,284 GLU.h
               2 File(s)         87,369 bytes
               2 Dir(s)  191,961,296,896 bytes free

Looks to me like you have to install the other header file by hand, per instructions here.