SFML community forums
Help => General => Topic started by: jaay_ on September 10, 2016, 07:42:20 pm
-
Hello! I've been having this error for a couple days and I can't find a way to fix it. If I include SFML/OpenGL.hpp during the build it says this:
c:\mingw\include\sfml\opengl.hpp:46:23: fatal error: GL/gl.h: No such file or directory
I'm using MinGW on windows, my IDE is CLion and CLion uses CMake.
Here's the full error log:
Scanning dependencies of target LearningOpenGL
[ 50%] Building CXX object CMakeFiles/LearningOpenGL.dir/src/main.cpp.obj
In file included from C:\My\folder\path\src\main.cpp:4:0:
c:\mingw\include\sfml\opengl.hpp:46:23: fatal error: GL/gl.h: No such file or directory
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles/LearningOpenGL.dir/src/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/LearningOpenGL.dir/all] Error 2
CMakeFiles\LearningOpenGL.dir\build.make:62: recipe for target 'CMakeFiles/LearningOpenGL.dir/src/main.cpp.obj' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/LearningOpenGL.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/LearningOpenGL.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/LearningOpenGL.dir/rule] Error 2
mingw32-make.exe: *** [LearningOpenGL] Error 2
Makefile:117: recipe for target 'LearningOpenGL' failed
And here's my code:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
P.S. It works fine when SFML/OpenGL.hpp isn't included.
-
You need the Windows SDK installed to have GL/gl.h on Windows. (Google for it to get the right version for your OS)
-
I just tried that and I moved the GL folder to my MinGW include folder but it now errors with:
fatal error: winapifamily.h: No such file or directory
I tried moving that over but it just keeps throwing errors!
-
I managed to get it compiling but when I compile this code:
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
bool running = true;
while (running)
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
running = false;
else if (event.type == sf::Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.display();
}
return 0;
}
It throws this error:
C:/path/to/my/project/src/main.cpp:28: undefined reference to `__imp_glViewport'
C:/path/to/my/project/src/main.cpp:33: undefined reference to `__imp_glClear'
-
You need to link OpenGL.
-
How? Sorry I'm pretty new to this.
-
Add OpenGL32.lib as an input in your linker options.
Instead of copying the GL folder, a better option would have been to add the Windows SDK include directories as additional include directories for your project.
-
I've managed to link OpenGL but it's still throwing errors! I've compiled SFML myself and I had to disable SFML_OPENGL_ES does that matter? Whenever I compile with that enabled it throws:
fatal error: EGL/egl.h: No such file or directory
Do you know how to fix that?
-
If you want to develop for Android and/or iOS (where OpenGL ES is used), you need the respective SDKs.
If you don't need Android support (Since you're on Windows, iOS isn't relevant here. OSX is needed), don't worry about it.