linking error in glut.h

I tried to compile the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <GL/gl.h>
#include <GL/glut.h>
void display()
{
     glClear(GL_COLOR_BUFFER_BIT);
     glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(512,512);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutCreateWindow("The glut hello world program");
    glutDisplayFunc(display);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glutMainLoop(); // Infinite event loop
    return 0;
}


but my compiler said there were linking errors and that the source programme wasn't created. What can I do?
Last edited on
Make sure you've included the required openGL libraries.
I have included them:

#include <GL/glut.h>
You misunderstand. You need to include (or specify) the proper libraries to link when you compile. At a minimum, that will include libglut, libGLU, and libGL. (These names may not be what you need. You will have to read the instructions that came with your OpenGL package. For example, you may have to link with libopengl32...)

If you are compiling from the command prompt, tack the following on to the end of your compile command:

  -lglut -lGLU -lGL

If you are using an IDE, go to the Project tab and find the part where you add libraries to link and make sure to add them.

Good luck!
I haven't understood what I have to do. I use DEV-C++ IDE. There isn't a Project tab for adding libraries. In the include file of the IDE's files there are the glut.h, the glu.h and the gl.h.

These are compliler's messages, I hope they might help:
1
2
3
4
5
6
7
8
9
10
11
  [Linker error] undefined reference to `_imp____glutInitWithExit@12' 
  [Linker error] undefined reference to `_imp____glutCreateWindowWithExit@8' 
  [Linker error] undefined reference to `_imp____glutCreateMenuWithExit@8' 
  [Linker error] undefined reference to `glClear@4' 
  [Linker error] undefined reference to `glFlush@0' 
  [Linker error] undefined reference to `_imp__glutInitWindowSize@8' 
  [Linker error] undefined reference to `_imp__glutInitDisplayMode@4' 
  [Linker error] undefined reference to `_imp__glutDisplayFunc@4' 
  [Linker error] undefined reference to `glClearColor@16' 
  [Linker error] undefined reference to `_imp__glutMainLoop@0' 
  ld returned 1 exit status 
Programming requires a great deal of brainpower and attention to details. You need to start using both. There is a very prominent menu item at the very top of your program IDE called "Project".

Start the IDE, press Alt-P, go to the "Parameters" tab, and enter the proper linker options in the "Linker" field:

  -lglut
  -lGLU
  -lGL

It took me all of 30 seconds to look up how to do this on the internet (since I don't use Dev-C++).

Since this is a new topic for you, it might be worth your time to read up a bit on how to use libraries and how to manage project options.

Good luck!
Last edited on
Thank you, I found the field and added the -lglut-lGLU-lGL but still it doesn't compile because of [Build Error] ["qu'est ce que c'est.o"] Error 1. What's the next step?
Topic archived. No new replies allowed.