title: c++ OpenGL undefined references
body: <p>I am trying to get OpenGL to work on my linux machine using c++ by following this <a href="http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/text.php" rel="nofollow noreferrer">tutorial</a></p>
  <p>I am using Ubuntu 12.04 LTS. I have both packages  <code>freeglut3-dev</code> and <code>mesa-common-dev</code> which I installed by <code>sudo apt-get install package-name1 package-name2</code></p>
  <p>Just to be sure I went to the recommended directory <code>/usr/include/GL</code> and listed the files with <code>ls</code>:</p>
  <pre><code>freeglut_ext.h  freeglut.h  freeglut_std.h  glext.h  gl.h  gl_mangle.h  glu.h  glu_mangle.h  glut.h  glxext.h  glx.h  glx_mangle.h  internal
  </code></pre>
  <p>I noted that I do have <code>gl.h</code> and <code>glut.h</code> so I tested the sample program as recommended by the tutorial. I downloaded the zip file, unzipped the files into the same directory and then ran the <code>make</code> utility. Here is some output after running <code>make</code></p>
  <pre><code>g++ -Wall -o cube main.cpp imageloader.cpp -lglut
  imageloader.cpp: In function ‘Image* loadBMP(const char*)’:
  imageloader.cpp:141:2: warning: suggest parentheses around ‘&amp;&amp;’ within ‘||’ [-Wparentheses]
  /tmp/ccWT2wvp.o:main.cpp:function loadTexture(Image*): error: undefined reference to 'glGenTextures'
  /tmp/ccWT2wvp.o:main.cpp:function loadTexture(Image*): error: undefined reference to 'glBindTexture'
  /tmp/ccWT2wvp.o:main.cpp:function loadTexture(Image*): error: undefined reference to 'glTexImage2D'
  </code></pre>
  <p>I got about  20 other undefined reference errors. So, it must be that I do not have something installed correctly, or am missing files. I do note that I checked the hardware acceleration info by running <code>glxinfo</code> and I do have hardware acceleration.</p>
  <ol>
  <li>How can I get OpenGL to work using c++</li>
  </ol>
  <p><strong>EDIT</strong> If I use a combination of both answers proved it works: Specifically I did the following:</p>
  <pre><code>someonespc:~/c++$ ls
  imageloader.cpp  imageloader.h  main.cpp  Makefile  Makefile~  vtr.bmp
  d2b2@d2b2-Aspire-7745G:~/c++$ g++ -Wall -lGL -o cube main.cpp imageloader.cpp -lglut -lGLU
  imageloader.cpp: In function ‘Image* loadBMP(const char*)’:
  imageloader.cpp:141:2: warning: suggest parentheses around ‘&amp;&amp;’ within ‘||’ [-Wparentheses]
  someonespc:~/c++$ ls
  cube  imageloader.cpp  imageloader.h  main.cpp  Makefile  Makefile~  vtr.bmp
  </code></pre>
  <p>Then I ran <code>./cube</code> and it worked! Please explain why putting <code>-lGL</code> and <code>-lGLU</code> worked</p>