问题
I have project on Qt4.8 and trying to build it with Qt5.1. I receive lots of
#error gl.h included before glew.h
and
#error glext.h included before glew.h
errors. Seems like it was big changes in Qt5 with OpenGL.. All includes are
#include "GL/glew.h"
#include "GL/gl.h"
#include "GL/glu.h"
glew.h is always the first.
回答1:
It doesn't matter whether the header is included first in some .h file. Header files are not standalone. What matters is the order that includes are seen from the source file.
You seem to have too many header inclusions (generally speaking, you should keep header-to-header inclusions to an absolute minimum). There's nothing that can be done on our end to fix that; you just need to untangle your header issues.
回答2:
Suposing you only use OPENGL calls in a class where you use functions you need to load using GLEW, then this will work.
What i did to fix this is to include all GLEW h's in the .CPP file, but BEFORE the inclusion of the header file (where the QTGUI which in turn contains OPENGL).
So this is the way for me in GLWIDGET.CPP:
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GLWidget.h>
As you can see, my GLWidget is a derived class coming from QGLWidget, which needs to include QTGUI and all of that.
来源:https://stackoverflow.com/questions/15479374/opengl-wih-qt5-error-gl-h-included-before-glew-h