C++ #error gl.h 包含在 glew.h 之前
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8580675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#error gl.h included before glew.h
提问by GarrickW
So I'm trying to move my OpenGL code from Main() into a specific class that will handle the 3D graphics only when necessary. Previously, the top of my main.cpp file looked like this:
所以我试图将我的 OpenGL 代码从 Main() 移动到一个特定的类中,该类仅在必要时处理 3D 图形。以前,我的 main.cpp 文件的顶部是这样的:
#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Game.h"
This worked well enough. What I tried to do was move all the OpenGL-relevant code into methods of the Game
class. So I removed #define GLEW_STATIC
and #include <GL/glew.h>
from the above, and put them into Game.h, such that the top of Game.h now looks like this:
这工作得很好。我试图做的是将所有与 OpenGL 相关的代码移动到Game
类的方法中。所以我删除#define GLEW_STATIC
,并#include <GL/glew.h>
从上面的,并把它们放到Game.h,这样Game.h的顶部,现在看起来是这样的:
#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Environment.h"
When I try to compile, I get the title error, #error gl.h included before glew.h
.
当我尝试编译时,出现标题错误#error gl.h included before glew.h
.
Why is this happening, and how can I use OpenGL code (almost) entirely inside the functions of a specific class without this happening?
为什么会发生这种情况,我怎样才能(几乎)完全在特定类的函数内使用 OpenGL 代码而不会发生这种情况?
EDIT:
编辑:
I have also tried this configuration in main.cpp, in an attempt to make sure that nothing includes SFML before GLEW.
我也在 main.cpp 中尝试了这个配置,以确保在 GLEW 之前没有包含 SFML。
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Game.h"
#include <SFML/Graphics.hpp>
Unfortunately, that doesn't help (there's nothing else being included that I'm not mentioning here).
不幸的是,这无济于事(我在这里没有提到任何其他内容)。
回答by R. Martinho Fernandes
Some other library is including gl.h. My guess would be SFML. Make sure you include GLEW first in Game.h and check the places where you include Game.h to make sure you're not including SFML or something else that includes gl.h before Game.h.
其他一些库包括 gl.h。我的猜测是SFML。确保首先在 Game.h 中包含 GLEW 并检查包含 Game.h 的位置,以确保在 Game.h 之前不包含 SFML 或其他包含 gl.h 的内容。
If you have something like:
如果你有类似的东西:
#include <something_that_includes_gl.h>
#include "Game.h"
It will effectively include gl.h before GLEW.
它将在 GLEW 之前有效地包含 gl.h。
回答by Mario
I think I had this issue once, too. It's somehow caused by the way SFML (1.6?) includes the OpenGL stuff.
我想我也遇到过这个问题。这在某种程度上是由 SFML(1.6?)包含 OpenGL 内容的方式引起的。
IIRC (been some time and I don't need GLEW anymore since switching to SFML2) it's due to SFML's Graphics.hpp including GLEW.h, too. Shouldn't happen due to include guards, but I think with some versions this might still happen. It might be possible for you to skip GLEW's header completely, as it's included through SFML anyway.
IIRC(已经有一段时间了,自从切换到 SFML2 后我不再需要 GLEW)这是由于 SFML 的 Graphics.hpp 也包括 GLEW.h。由于包含守卫,不应该发生,但我认为在某些版本中这可能仍然会发生。您可能可以完全跳过 GLEW 的标头,因为它无论如何都包含在 SFML 中。
Which version of SFML are you running? 1.6, 2.0 or the 2.0 with the new API? Also, what's the reason for using GLEW? Something you're missing from SFML? Maybe it's something included in the latest version, so keeps you from having to include it too.
您正在运行哪个版本的 SFML?1.6、2.0 还是带有新 API 的 2.0?另外,使用 GLEW 的原因是什么?您在 SFML 中遗漏了什么?也许它包含在最新版本中,因此您不必也包含它。