<p>You need to link with the OpenGL library. Try adding <code>-lgl</code> to the compilation command.</p>

CC BY-SA 3.0
2017-06-19T14:53:41.643Z
I did try adding -lgl to the compilation command on seeing this suggestion on one of the internet sites. But it does not help
SAK
CC BY-SA 3.0
2017-06-19T06:49:26.527Z
2017-06-19T06:49:26.527Z
Julien Guertault
<p>I am trying to run the following program on ubuntu 15.04. However on typing &quot;g++ pgm1.cpp -lglut&quot;
I am getting following errors</p>
<p><strong>/usr/bin/ld: /tmp/cc9aXqhZ.o: undefined reference to symbol 'glClear'</strong></p>
<p><strong>/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line</strong></p>
<p>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.</p>
<pre><code># include &quot;GL/freeglut.h&quot;
# include &quot;GL/gl.h&quot;
# include &lt;GL/glut.h&gt;

void init(void)
{
    glClearColor(0.0f,0.0f,1.0f,1.0f);
}
void display (void) 
{
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}
int main (int argc, char** argv)
{
    glutInit(&amp;argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutCreateWindow(&quot;A Blank Window&quot;);
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}
</code></pre>

CC BY-SA 3.0
2017-06-18T17:28:50.323Z
1. try update your system. and run `ldconfig`
2. how did you compile your code? what arguments are you using?
Mary Chang
CC BY-SA 3.0
2017-06-19T14:52:37.567Z
I used following commands: "g++ pgm1.cpp -lglut"
SAK
CC BY-SA 3.0
2017-06-19T15:13:12.047Z
I tried running ldconfig command. I am getting a message "Cant create temporary cache file/etc/ld.so.cache~: Permission denied"
SAK
CC BY-SA 3.0
2017-06-19T18:23:33.920Z
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)
Mary Chang
CC BY-SA 4.0
2022-02-16T13:16:35.680Z
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.
pmw1234
<opengl>
Errors on Compiling my first program on OpenGL on Ubuntu
SAK
# Errors on Compiling my first program on OpenGL on Ubuntu

(Asked by: username_0 on 2017-06-18)

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)
{
    glClearColor(0.0f,0.0f,1.0f,1.0f);
}
void display (void) 
{
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}
int main (int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutCreateWindow("A Blank Window");
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

```

**Tags:** opengl

> **Comments:**
> **username_1**: 1. try update your system. and run `ldconfig` 2. how did you compile your code? what arguments are you using?  
> **username_0**: I used following commands: "g++ pgm1.cpp -lglut"  
> **username_0**: I tried running ldconfig command. I am getting a message "Cant create temporary cache file/etc/ld.so.cache~: Permission denied"  
> **username_1**: 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)  
> **username_2**: 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.  

---

## 1 answers

### Answer by username_3 on 2017-06-19. Score: 4

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

> **Comments:**
> **username_0**: I did try adding -lgl to the compilation command on seeing this suggestion on one of the internet sites. But it does not help  

---

