title: Link error when trying to build a simple OpenGL program
body: <p>This is the OpenGL code:</p>
  
  <pre><code>#include &lt;GL/glut.h&gt;
  void display()
  {
   glClear(GL_COLOR_BUFFER_BIT);
  }
  
  int main(int argc,char **argv)
  {
     glutInit(&amp;argc,argv);
     glutCreateWindow("Hello,world!");
     glutDisplayFunc(display);
     glutMainLoop();
  }
  </code></pre>
  
  <p>The error messages are:</p>
  
  <pre><code>"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
  make[1]: Entering directory `/home/zh/workspace/OpenGL/CppApplication_1'
  "/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_1
  make[2]: Entering directory `/home/zh/workspace/OpenGL/CppApplication_1'
  mkdir -p dist/Debug/GNU-Linux-x86
  g++ -lglut -lGLU -lGL -lGLEW    -o dist/Debug/GNU-Linux-x86/cppapplication_1 build/Debug/GNU-Linux-x86/main.o -L/usr/lib/x86_64-linux-gnu -Wl,-rpath,/usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libglut.so /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLEW.so /usr/lib/x86_64-linux-gnu/libGLEWmx.so
  /usr/bin/ld: build/Debug/GNU-Linux-x86/main.o: undefined reference to symbol 'glClear'
  /usr/lib/x86_64-linux-gnu/libGL.so: error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  make[2]: *** [dist/Debug/GNU-Linux-x86/cppapplication_1] Error 1
  make[2]: Leaving directory `/home/zh/workspace/OpenGL/CppApplication_1'
  make[1]: *** [.build-conf] Error 2
  make[1]: Leaving directory `/home/zh/workspace/OpenGL/CppApplication_1'
  make: *** [.build-impl] Error 2
  
  BUILD FAILED (exit value 2, total time: 124ms)
  </code></pre>
  
  <p>At first I had thought this is because the OpenGL version installed is too low, but <code>glClear</code> is available from OpenGL 1.0 and exists in all versions (<a href="http://www.opengl.org/wiki/GlClear" rel="nofollow noreferrer">see here</a>). This is version information of the OpenGL on my system.
  <img src="https://i.stack.imgur.com/9jryS.png" alt="enter image description here"></p>
  
  <p>I built the freeglut 2.8.1 and glew 1.10.0 and have them installed in my system:
  <img src="https://i.stack.imgur.com/KWQ0n.png" alt="enter image description here"></p>
  
  <p>I included the path to the library and specified needed library in the environment:
  <img src="https://i.stack.imgur.com/19Jk6.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/szZw2.png" alt="enter image description here"></p>
  
  <p>Also, I have read related threads in repository: <a href="https://stackoverflow.com/questions/5204818/simple-opengl-program-fails-to-link-in-ubuntu">enter link description here</a>, <a href="https://stackoverflow.com/questions/6851557/why-wont-this-glut-program-compile-am-i-missing-libraries-or-headers">enter link description here</a>, but they don't help.</p>
  
  <p>I'm worn out and really can not find what I am missing to build such a simple OpenGL code. Could you please tell me how to troubleshoot this problem? Thank you.</p>
  
  <p>The environment I am using are:
  Ubuntu 14.04 (64 bit)+
  NetBeans 8.0</p>
  
  <p>A hint: when I commented the glClear out, the program can be built successfully.</p>
  
  <p>Edit: For those who working on windows 7 and encountering similar linking problem (OpenGL function not found), Vishwanath gowda's answer in <a href="https://stackoverflow.com/questions/12171317/how-do-you-install-glut-and-opengl-in-visual-studio-2012">this</a> thread may help.</p>
  
  <p>Edit2: We know that Windows supports OpenGL poorly, if you are at the same time using Intel's entrance-level integrated graphics card for which intel's driver provides no additional support of OpenGL, you'll have to make a new Mesa's OpenGL libray according to the guide <a href="https://stackoverflow.com/questions/17871781/building-mesa-for-windows-7-mesa-9-1">here</a>. This can be done because OpenGL is independent of hardware so can be implemented solely by software (A <a href="http://www.opengl-redbook.com/" rel="nofollow noreferrer">book</a> claims so). Be careful to use machine=x86_64 if you are working on 64bit Win7. You can check that by observing the output of dumpbin /headers youropengldll.dll|more. You can also check that the functionality of OpenGL on your windows system is enhanced after that using a software "OpenGL Extension Viewer".</p>