Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML errors when compiling if OpenGL.hpp is included.  (Read 4072 times)

0 Members and 1 Guest are viewing this topic.

jaay_

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
SFML errors when compiling if OpenGL.hpp is included.
« 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.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #1 on: September 11, 2016, 07:25:07 am »
You need the Windows SDK installed to have GL/gl.h on Windows. (Google for it to get the right version for your OS)

jaay_

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #2 on: September 11, 2016, 01:39:46 pm »
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!

jaay_

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #3 on: September 11, 2016, 02:22:01 pm »
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'

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: SFML errors when compiling if OpenGL.hpp is included.
« Reply #4 on: September 11, 2016, 03:30:03 pm »
You need to link OpenGL.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jaay_

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #5 on: September 11, 2016, 03:35:52 pm »
How? Sorry I'm pretty new to this.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #6 on: September 11, 2016, 10:22:19 pm »
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.

jaay_

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #7 on: September 11, 2016, 10:30:08 pm »
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?

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: SFML errors when compiling if OpenGL.hpp is included.
« Reply #8 on: September 12, 2016, 01:59:00 am »
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.