There is a macro definition clash between Glew's glew.h and Mesa Glut's glut.h on Unix. Any program using Glew fails to compile. The problem does NOT occur with other Glut implementations (freeglut, Kilgard glut).
I am using Slackware Linux 12.0, Mesa 6.5.2 and Glew 1.5.0. However, the problem is present in all recent versions of Glew, including svn, and all recent versions of Mesa Glut, including git.
Other people have had the same problem:
I first encountered this problem when trying to compile enblend, but even the following trivial test program is sufficient to demonstrate the problem (thanks Philippe Després). It doesn't compile.
- First, the application #includes glew.h
- glew.h #defines GLAPIENTRY -- for Unix this is line 209 of glew.h, and GLAPIENTRY is defined to be empty
- Then glew.h #includes glu.h at line 1137
- Then glu.h #includes gl.h which redefines GLAPIENTRY (consistently with glew.h)
- Then glew.h uses GLAPIENTRY (successfully), and eventually #undefs GLAPIENTRY at line 10767
- Then the application #includes glut.h
- Then glut.h #includes glu.h at line 11
- But glu.h has already been included, so glu.h does nothing (it checks __glu_h__ in the usual way)
- Then glut.h uses GLAPIENTRY at line 196
# define GLUTAPIENTRY GLAPIENTRY
In other words, glut.h expects to get GLAPIENTRY from glu.h, but glew.h undefined it.
- So GLUTAPIENTRY now contains the string "GLAPIENTRY" instead of being empty. This causes compilation errors throughout the rest of glut.h, starting on line 531
GLUTAPI void GLUTAPIENTRY glutInit(int *argcp, char **argv);
which produces these errors
/usr/include/GL/glut.h:531: error: expected initializer before 'glutInit'
/usr/include/GL/glut.h:539: error: expected initializer before 'glutInitDisplayMode'
/usr/include/GL/glut.h:541: error: expected initializer before 'glutInitDisplayString'
/usr/include/GL/glut.h:543: error: expected initializer before 'glutInitWindowPosition'
/usr/include/GL/glut.h:544: error: expected initializer before 'glutInitWindowSize'
The obvious solution is to delete the #undef at line 10767 of glew.h. Here's the trivial patch:
--- glew-1.5.0/include/GL/glew.h 2007-12-28 03:09:49.000000000 +0000
+++ glew-patched/include/GL/glew.h 2008-01-26 11:45:27.000000000 +0000
@@ -10764,7 +10764,6 @@