views:

938

answers:

3

Compiling a file that uses OpenGL with Visual C++, when I try to include the gl.h header file I get about 150 unhelpful compile errors:

error C2144: syntax error : 'void' should be preceded by ';'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2146: syntax error : missing ';' before identifier 'glAccum'

etc.

+1  A: 

Sounds like you're including a C header inside a C++ project. Try enclosing your include statement inside:

extern "C" {
#include "gl.h"
}
Ates Goral
+1  A: 

The first possibility to consider is that the compiler's messages are actually right. Surely there were line numbers included in those error messages, so have you looked at the offending lines, and some of the lines preceding them, to try to identify what might really be the cause?

Were there any other messages that came before the ones you've cited? (A missing header, for instance?) Always start addressing compiler messages from the first one; later ones are sometimes just side effects caused by that.

Can you reproduce the problem in a simple project? Is it enough to just write #include <gl.h> in an otherwise empty file and try to compile it? Or is there more about this source code that causes the error to occur?

Remember that you're the one here with access to your code; the questions I'm asking above are the sorts of things you need to consider since you can't always have someone else debug your code for you.

Rob Kennedy
+5  A: 

Just #include <windows.h> before <gl/gl.h> or <gl/glu.h>. It is needed for some types, such as WINGDIAPI and APIENTRY.

starmole
+1 This is the right answer.
ChrisN