0
votes

I am new to C/C++ environment setup. Right now I am using Eclipse IDE. Below are the steps I have followed After installing MinGW and running basic HelloWorld, C program 1) Copied glew32.dll and glut32.dll to "C:\MinGW\bin" 2) Copied gl.h, glew.h, glu.h and glut.h to "C:\MinGW\include\GL" 3) Copied glew32.lib, glut32.lib and OPENGL32.LIB to "C:\MinGW\lib" 4) In Project->properties->C/C++ Build->Settings->Tool Settings->MinGW C Linker->Libraries(-l) added "glew32", "glut32","glu32" and "opengl32" 5) Copied below code

Compiles properly.

The moment I uncomment the first line, ie glew.h, glut related compile errors (added below) appear, Can any one tell me where I am going wrong during setup?

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

void changeViewport(int w, int h)
{
    glViewport(0, 0, w, h);
}

void render()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}


int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Pinnen is the best");
    glutReshapeFunc(changeViewport);
    glutDisplayFunc(render);
    glutMainLoop();
    return 0;
}


Description Resource    Path    Location    Type
undefined reference to `__glutCreateMenuWithExit'   OpenGL      line 549, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `__glutCreateWindowWithExit' OpenGL      line 503, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `__glutInitWithExit' OpenGL      line 486, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `glutDisplayFunc'    OpenGL.c    /OpenGL/src line 25 C/C++ Problem
undefined reference to `glutInitDisplayMode'    OpenGL.c    /OpenGL/src line 21 C/C++ Problem

//ignore

1
Are you linking with glut and glew? How are you compiling this? - Colonel Thirty Two
I am new to C/C++ environment setup. Right now I am using Eclipse IDE. Below are the steps I have followed After installing MinGW and running basic HelloWorld, C program 1) Copied glew32.dll and glut32.dll to "C:\MinGW\bin" 2) Copied gl.h, glew.h, glu.h and glut.h to "C:\MinGW\include\GL" 3) Copied glew32.lib, glut32.lib and OPENGL32.LIB to "C:\MinGW\lib" 4) In Project->properties->C/C++ Build->Settings->Tool Settings->MinGW C Linker->Libraries(-l) added "glew32", "glut32","glu32" and "opengl32" 5) Copied above code After compiling I get compile errors mentioned above. - user2978111
You are still unclear in your question. In compiled version of program #include glew.h is commented or not? If you don't want to use glew, why you are linking it to the compiler? And as I stated in my answer if you want to use glew, delete #include gl.h statement. Btw, glut is very old library I suggest you to use glfw or freeglut instead. - Berke Cagkan Toptas
Sorry for the confusion. Code compiles fine when I comment the first line and starts showing errors moment I uncomment the first line. - user2978111
Thanks a LOT. I am able to compile and run my code with glew.h line uncommented. As you suggested, there seems to be problem with glut.h. No more errors after using freeglut.h. Thank you once again. - user2978111

1 Answers

1
votes

From glew webpage [delete gl include] :

Using GLEW as a shared library

in your program:

#include <GL/glew.h>
#include <GL/glut.h>
<gl, glu, and glut functionality is available here>

or:

#include <GL/glew.h>
<gl and glu functionality is available here>

Remember to link your project with glew32.lib, glu32.lib, and opengl32.lib on Windows and libGLEW.so, libGLU.so, and libGL.so on Unix (-lGLEW -lGLU -lGL). It is important to keep in mind that glew.h includes neither windows.h nor gl.h. Also, GLEW will warn you by issuing a preprocessor error in case you have included gl.h, glext.h, or glATI.h before glew.h.