I am trying to run the following program on ubuntu 15.04. However on typing "g++ pgm1.cpp -lglut" I am getting following errors

/usr/bin/ld: /tmp/cc9aXqhZ.o: undefined reference to symbol 'glClear'

/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line

Though I am familiar with C programming in Codeblocks and DevC++, this is the first time I am working on Ubuntu and OpenGL. I installed ubuntu and files related to OpenGL based on information available on the net. The sample program too is from the internet. I would request help in getting the program run. Thanks.

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

void init(void)
void display (void) 
int main (int argc, char** argv)
    glutCreateWindow("A Blank Window");
    return 0;
  • 1
    $\begingroup$ 1. try update your system. and run ldconfig 2. how did you compile your code? what arguments are you using? $\endgroup$
    – Mary Chang
    Jun 18, 2017 at 17:28
  • $\begingroup$ I used following commands: "g++ pgm1.cpp -lglut" $\endgroup$
    – SAK
    Jun 19, 2017 at 14:52
  • $\begingroup$ I tried running ldconfig command. I am getting a message "Cant create temporary cache file/etc/ld.so.cache~: Permission denied" $\endgroup$
    – SAK
    Jun 19, 2017 at 15:13
  • $\begingroup$ try sudo ldconfig. When you see Permission denied. adding sudo to the command will fix that 99% of the time(not the best habit though) $\endgroup$
    – Mary Chang
    Jun 19, 2017 at 18:23
  • $\begingroup$ This isn't really a graphics question, it is more of programming/linker question and the folks over at stack overflow will probably have an answer, I recommend moving the question over there. $\endgroup$
    – pmw1234
    Feb 16, 2022 at 13:16

1 Answer 1


You need to link with the OpenGL library. Try adding -lgl to the compilation command.

  • $\begingroup$ I did try adding -lgl to the compilation command on seeing this suggestion on one of the internet sites. But it does not help $\endgroup$
    – SAK
    Jun 19, 2017 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.