0

OpenGL functions not found

I installed GLEW, GLUT and GLFW for MinGW on Windows. Put all of the header files into C:\MinGW\include\GL and C:\MinGW\incude\GLFW. Copied the glew32.dll,glfw3.dll and freeglut.dll binaries to a folder where i had this script:

#include <GL/glew.h>
#include <GL/glut.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;


int main( int argc, char* args[] )
{
glutInit(&argc, args);
glutCreateWindow("GLEW Test");

GLenum err = glewInit();

if (GLEW_OK != err)
{
  cout << "Error:\n" << err;

}
cout << glewGetString(GLEW_VERSION);
}

I compiled it using g++ glewtest.cpp -o glewtest -lfreeglut -lglew32 -lglfw3 and when i ran it a window named "GLEW Test" popped up for a second and the version of glew "2.1.0" was printed in the terminal.

Then i wanted to add some content to the window and i found a example script on the web to do that:

#include <GL/gl.h>
#include <GL/glut.h>

void renderScene(void) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
        glVertex3f(-0.5,-0.5,0.0);
        glVertex3f(0.5,0.0,0.0);
        glVertex3f(0.0,0.5,0.0);
    glEnd();

        glutSwapBuffers();
}

int main(int argc, char **argv) {

    // init GLUT and create Window
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(320,320);
    glutCreateWindow("Lighthouse3D - GLUT Tutorial");

    // register callbacks
    glutDisplayFunc(renderScene);

    // enter GLUT event processing cycle
    glutMainLoop();

    return 1;
}

But when compiling it this time using the same command i just got a lot of errors like:

c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Mmm\AppData\Local\Temp\cckUUJHk.o:glewtest.cpp:(.text+0x7c): undefined reference to `glClear@4'

I didn't find any helpful resources and no matter what i did it always failed to compile. Did somebody else ever encounter such an issue too? How can i resolve this?

Mmm
  • 1
  • 3
  • Why isn't your second program `#include`ing `GL/glew.h`? – genpfault Feb 07 '20 at 15:00
  • I would expect the compile/link command to have `-lGL` at the end, no? – G.M. Feb 07 '20 at 15:06
  • When i added glew the compiler freaked out: `c:\mingw\include\gl\glew.h:14338:73: error: 'GLuint64' does not name a type; did you mean 'GLuint'? typedef void (GLAPIENTRY * PFNGLDRAWCOMMANDSSTATESADDRESSNVPROC) (const GLuint64* indirects, const GLsizei* sizes, const GLuint* states, const GLuint* fbos, GLuint count);` – Mmm Feb 07 '20 at 15:11
  • @G.M. It's `-lOpenGL32` for Windows, probably together with `-lGdi32`. – flyx Feb 07 '20 at 15:20
  • @flyx yep adding the -lOpenGL32 flag fixed it – Mmm Feb 07 '20 at 15:23

0 Answers0