0

I'm trying to start learing opengl and I use VS2010 ultimate sp1 but when I add opengl headers I'm getting errors which indicate that there are errors in files not created by me.

#include "stdafx.h"
#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

errors (195 in total) this is I think the most common one:
Error 1 error C2008: '$' : unexpected in macro definition C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h 142

7
  • Have you tried using GLee? ( opengl.org/sdk/libs/GLee )
    – James
    Commented Aug 16, 2011 at 19:19
  • 5
    What is the first error message? Commented Aug 16, 2011 at 19:20
  • Obviously the _ PREFAST _ macro is defined. But I don't really know what causes it. As you are using VS2010 ultimate you may have switched on a wrong option that causes this. Google reveals it may have to do with some code analysing tool (called PREfast). As a workaround try recreating your project with default options. Commented Aug 16, 2011 at 19:27
  • make an empty project. and include opengl libs and header to the project. There shouldn't be any errors
    – Gasim
    Commented Aug 16, 2011 at 19:29
  • 2
    Slightly Off Topic: You should not use backslashes in include directives but regular forward slashes. Also you should use the proper case of the include file names, which are GL/gl.h, GL/glu.h and windows.h. Last but not least you should surround your inclusion of windows.h with tests for the _WIN32 macro: #ifdef _WIN32 #include <windows.h> #endif
    – datenwolf
    Commented Aug 16, 2011 at 19:38

2 Answers 2

5

Please check that you didn't disable Microsoft C++ extensions. $ as a part of identifiers is a part of these extensions, so driverspecs.h won't compile when they are disabled. Command line switch is /Za, also this option is the top-most in Language section in project properties in Visual Studio

0

My first guess would be windows.h stuff conflicting with opengl definitions. You don't really need windows.h for a simple command line application like this one. Another possibility is the precompiled headers option (stdafx.h) I usually disable it in the compiler options when I deal with OpenGL and other cross platform projects as dependencies they bring in usually don't agree well with ported code

5
  • You still need to include windows.h; you can't create a window without one. And you can't initialize OpenGL without creating a window. Commented Aug 16, 2011 at 21:12
  • That depends on whether he is trying to use GLUT or WGL. GLUT wouldn't require library user to include OS specific headers.
    – AlexK
    Commented Aug 16, 2011 at 23:33
  • And this brings up another question: which implementation of OpenGL are you trying to use ?
    – AlexK
    Commented Aug 16, 2011 at 23:48
  • @AlexK: Actually on Windows you have to include windows.h before GL/gl.h because the Windows variant of that header makes use of some macros defined therein. So it's become canonical to add a #ifdef _WIN32 #include <windows.h> #endif in OpenGL code meant to be portable.
    – datenwolf
    Commented Aug 16, 2011 at 23:56
  • @AlexK well, that's the headers supplied with VS so I suppose it's theirs?
    – user336635
    Commented Aug 17, 2011 at 14:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.