title: Ubuntu 13.10 C++ OpenGL GLUT - linking issues - undefined reference to `glClearColor'
body: <p>I am running Ubuntu 13.10 and trying to compile that portion of sample OpenGL code:</p>
  
  <pre><code>#include "GL/freeglut.h"
  #include "GL/gl.h"
  
  /* display function - code from:
       http://fly.cc.fer.hr/~unreal/theredbook/chapter01.html
  This is the actual usage of the OpenGL library.
  The following code is the same for any platform */
  void renderFunction()
  {
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glClear(GL_COLOR_BUFFER_BIT);
      glColor3f(1.0, 1.0, 1.0);
      glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
      glBegin(GL_POLYGON);
          glVertex2f(-0.5, -0.5);
          glVertex2f(-0.5, 0.5);
          glVertex2f(0.5, 0.5);
          glVertex2f(0.5, -0.5);
      glEnd();
      glFlush();
  }
  
  /* Main method - main entry point of application
  the freeglut library does the window creation work for us,
  regardless of the platform. */
  int main(int argc, char** argv)
  {
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_SINGLE);
      glutInitWindowSize(500,500);
      glutInitWindowPosition(100,100);
      glutCreateWindow("OpenGL - First window demo");
      glutDisplayFunc(renderFunction);
      glutMainLoop();
      return 0;
  }
  </code></pre>
  
  <p>I've used Eclipse to build the project, however it fails on linking level:</p>
  
  <pre><code>Building target: opengl_test
  Invoking: GCC C++ Linker
  g++ -L/usr/lib -L/usr/lib/fglrx -L/usr/lib/x86_64-linux-gnu -L/usr/lib/i386-linux-gnu/mesa -L/usr/lib/x86_64-linux-gnu/mesa -o "opengl_test"  ./src/opengl_test.o   
  ./src/opengl_test.o: In function `renderFunction()':
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:10: undefined reference to `glClearColor'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:11: undefined reference to `glClear'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:12: undefined reference to `glColor3f'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:13: undefined reference to `glOrtho'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:14: undefined reference to `glBegin'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:15: undefined reference to `glVertex2f'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:16: undefined reference to `glVertex2f'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:17: undefined reference to `glVertex2f'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:18: undefined reference to `glVertex2f'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:19: undefined reference to `glEnd'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:20: undefined reference to `glFlush'
  ./src/opengl_test.o: In function `main':
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:28: undefined reference to `glutInit'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:29: undefined reference to `glutInitDisplayMode'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:30: undefined reference to `glutInitWindowSize'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:31: undefined reference to `glutInitWindowPosition'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:32: undefined reference to `glutCreateWindow'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:33: undefined reference to `glutDisplayFunc'
  /var/www/opengl_test/Debug/../src/opengl_test.cpp:34: undefined reference to `glutMainLoop'
  collect2: error: ld returned 1 exit status
  make: *** [opengl_test] Error 1
  </code></pre>
  
  <p>... so I've tried G++:</p>
  
  <pre><code>g++ -lGL -lglut opengl_test.cpp  -o test
  </code></pre>
  
  <p>However it gives pretty much the same output as Eclipse one.</p>
  
  <p>I thought that maybe I need symlink necessary libs manually to /usr/lib.
  I've searched for libs:</p>
  
  <pre><code>$ sudo apt-file search libGL.so
  fglrx: /usr/lib/fglrx/libGL.so
  fglrx: /usr/lib/fglrx/libGL.so.1
  fglrx: /usr/lib/fglrx/libGL.so.1.2
  fglrx: /usr/lib32/fglrx/libGL.so.1.2
  fglrx-updates: /usr/lib/fglrx/libGL.so
  fglrx-updates: /usr/lib/fglrx/libGL.so.1
  fglrx-updates: /usr/lib/fglrx/libGL.so.1.2
  fglrx-updates: /usr/lib32/fglrx/libGL.so.1.2
  libgl1-mesa-dev: /usr/lib/x86_64-linux-gnu/libGL.so
  libgl1-mesa-dev: /usr/lib/x86_64-linux-gnu/mesa/libGL.so
  libgl1-mesa-glx: /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1
  libgl1-mesa-glx: /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
  libgl1-mesa-glx-dbg: /usr/lib/debug/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
  nvidia-173: /usr/lib/nvidia-173/libGL.so
  nvidia-173: /usr/lib/nvidia-173/libGL.so.1
  nvidia-173: /usr/lib/nvidia-173/libGL.so.173.14.37
  nvidia-173: /usr/lib32/nvidia-173/libGL.so
  nvidia-173: /usr/lib32/nvidia-173/libGL.so.1
  nvidia-173: /usr/lib32/nvidia-173/libGL.so.173.14.37
  nvidia-304: /usr/lib/nvidia-304/libGL.so
  nvidia-304: /usr/lib/nvidia-304/libGL.so.1
  nvidia-304: /usr/lib/nvidia-304/libGL.so.304.88
  nvidia-304: /usr/lib32/nvidia-304/libGL.so
  nvidia-304: /usr/lib32/nvidia-304/libGL.so.1
  nvidia-304: /usr/lib32/nvidia-304/libGL.so.304.88
  nvidia-304-updates: /usr/lib/nvidia-304-updates/libGL.so
  nvidia-304-updates: /usr/lib/nvidia-304-updates/libGL.so.1
  nvidia-304-updates: /usr/lib/nvidia-304-updates/libGL.so.304.108
  nvidia-304-updates: /usr/lib32/nvidia-304-updates/libGL.so
  nvidia-304-updates: /usr/lib32/nvidia-304-updates/libGL.so.1
  nvidia-304-updates: /usr/lib32/nvidia-304-updates/libGL.so.304.108
  nvidia-319: /usr/lib/nvidia-319/libGL.so
  nvidia-319: /usr/lib/nvidia-319/libGL.so.1
  nvidia-319: /usr/lib/nvidia-319/libGL.so.319.32
  nvidia-319: /usr/lib32/nvidia-319/libGL.so
  nvidia-319: /usr/lib32/nvidia-319/libGL.so.1
  nvidia-319: /usr/lib32/nvidia-319/libGL.so.319.32
  nvidia-319-updates: /usr/lib/nvidia-319-updates/libGL.so
  nvidia-319-updates: /usr/lib/nvidia-319-updates/libGL.so.1
  nvidia-319-updates: /usr/lib/nvidia-319-updates/libGL.so.319.60
  nvidia-319-updates: /usr/lib32/nvidia-319-updates/libGL.so
  nvidia-319-updates: /usr/lib32/nvidia-319-updates/libGL.so.1
  nvidia-319-updates: /usr/lib32/nvidia-319-updates/libGL.so.319.60
  primus-libs: /usr/lib/x86_64-linux-gnu/primus/libGL.so.1
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$ sudo apt-file search libglut.so
  freeglut3: /usr/lib/x86_64-linux-gnu/libglut.so.3
  freeglut3: /usr/lib/x86_64-linux-gnu/libglut.so.3.9.0
  freeglut3-dev: /usr/lib/x86_64-linux-gnu/libglut.so
  </code></pre>
  
  <p>Made symlinks:</p>
  
  <pre><code>sudo ln -s /usr/lib/fglrx/libGL.so /usr/lib/libGL.so
  sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so /usr/lib/libglut.so
  </code></pre>
  
  <p>However it still did not help. The same linking issue appeared.</p>
  
  <ol>
  <li>How do I debug that issue?</li>
  <li>How do I know which lib to choose and link them to /usr/lib? I chose fglrx, because my GPU drivers are running fglrx.</li>
  <li>Do I need each time to link library manually from /usr/lib..../somewhere to /usr/lib?</li>
  </ol>