PDA

View Full Version : C++ Style or C Style? Error on compiling...



DarkBrute
03-22-2005, 05:50 PM
When you are using openGL, do you code like in C or C++?

I tried to compile an example that I retyped from the red book, and I changed the format to C++. So instead of:

void reshape (int w, int h) I typed:

void reshape(int w, int h) Now, should this change have any effect on actual preformance? I don't know, so I compile it... Then I get these errors:


Compiling...
Main.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : error C2146: syntax error : missing ';' before identifier 'glAccum'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1136) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1136) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1136) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1136) : error C2146: syntax error : missing ';' before identifier 'glAlphaFunc'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1136) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1136) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1137) : error C2146: syntax error : missing ';' before identifier 'GLboolean'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1137) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1137) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1137) : error C2146: syntax error : missing ';' before identifier 'glAreTexturesResident'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1137) : error C2371: 'APIENTRY' : redefinition; different basic types
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1138) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1138) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1138) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1138) : error C2146: syntax error : missing ';' before identifier 'glArrayElement'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1138) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1138) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1139) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1139) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1139) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1139) : error C2146: syntax error : missing ';' before identifier 'glBegin'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1139) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1139) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1140) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1140) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1140) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1140) : error C2146: syntax error : missing ';' before identifier 'glBindTexture'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1140) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1140) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1141) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1141) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1141) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1141) : error C2146: syntax error : missing ';' before identifier 'glBitmap'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1141) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1141) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1142) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1142) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1142) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1142) : error C2146: syntax error : missing ';' before identifier 'glBlendFunc'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1142) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1142) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1143) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1143) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1143) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1143) : error C2146: syntax error : missing ';' before identifier 'glCallList'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1143) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1143) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1144) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1144) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1144) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1144) : error C2146: syntax error : missing ';' before identifier 'glCallLists'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1144) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1144) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1145) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1145) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1145) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1145) : error C2146: syntax error : missing ';' before identifier 'glClear'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1145) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1145) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1146) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1146) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1146) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1146) : error C2146: syntax error : missing ';' before identifier 'glClearAccum'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1146) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1146) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1147) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1147) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1147) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1147) : error C2146: syntax error : missing ';' before identifier 'glClearColor'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1147) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1147) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1148) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1148) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1148) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1148) : error C2146: syntax error : missing ';' before identifier 'glClearDepth'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1148) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1148) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1149) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1149) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1149) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1149) : error C2146: syntax error : missing ';' before identifier 'glClearIndex'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1149) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1149) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1150) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1150) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1150) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1150) : error C2146: syntax error : missing ';' before identifier 'glClearStencil'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1150) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1150) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1151) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1151) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1151) : error C2086: 'int WINGDIAPI' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'WINGDIAPI'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1151) : error C2146: syntax error : missing ';' before identifier 'glClipPlane'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1151) : error C2182: 'APIENTRY' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1151) : error C2086: 'int APIENTRY' : redefinition
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1135) : see declaration of 'APIENTRY'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1152) : error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1152) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\GL\gl.h(1152) : fatal error C1003: error count exceeds 100; stopping compilation
Now, did I do anything to the code? No, I simply typed word for word, letter for letter (except the changes to the style) as it was showed in the redbook.

How do I fix this?

mikael_aronsson
03-22-2005, 10:59 PM
Hi !

You made a typo in the message (the first and second example are identical...) so I am not sure what you mean, but if you talk about:

void func( int x, int y) { }

vs:

void func( x y)
int x, y
{ }

Then you should be aware that the second example is not allowed in C++, you must use the first version, if you try the second you get lots of weird compiler errors.

The way you define your functions have no impact at all on the actual generated code and performance, the result is identical.

Mikael

T101
03-22-2005, 11:06 PM
There is no difference between C and C++ function header syntax. (EDIT: except what the poster above stated - but that's not what you're doing)

W.r.t. the errors you're getting, they start with a header file: ...2003\Vc7\include\GL\gl.h

I presume that that's the standard OpenGL header. Not good.

My guess is that the problem is with the macro "WINGDIAPI" - it's not defined.

Perhaps the fix is as simple as including <windows.h> or <gdi.h> (or something similar) before you include GL/gl.h, although I have no idea why gl.h does not simply include that on its own.

jide
03-23-2005, 02:14 AM
It seems he first forgot a semicolon. This can be the main error producing a lot of other for the compiler.

void reshape (int w, int h);

should resolve almost all errors if that was the prototype you wrote.