title: OpenGL Compilation Errors Ubuntu
body: <p>I'm trying to set up the code from 
  <a href="http://www.openglsuperbible.com/example-code" rel="nofollow">http://www.openglsuperbible.com/example-code/</a></p>
  
  <p>with command:</p>
  
  <pre><code>$ cmake -G "Unix Makefiles" ; make clean ; make all
  </code></pre>
  
  <p>I've installed the following packages in order to prepare the system:</p>
  
  <pre><code>xrandr libxrandr x11-xserver-utils libxrandr-dev libglfw2 libglfw-dev xorg-dev libx11-dev libgl-dev libglu-dev libgl1-mesa-dev freeglut3 freeglut3-dev mesa-common-dev freeglut3-dev build-essential libx11-dev libx11-*
  </code></pre>
  
  <p>I may have missed some of the packages I've installed in this list, I apologize.</p>
  
  <p>Then I've modified the CMakeList.txt in order to add to the linking phase the following things:</p>
  
  <pre><code>glfw GL rt glut X11 dl Xrandr Xext GLEW GLU
  </code></pre>
  
  <p>Then I try to compile, but it fails at the linking phase:</p>
  
  <pre><code>/opt/sb6code/src/xraw/xraw.c: In function ‘CreateWindow’:
  /opt/sb6code/src/xraw/xraw.c:106:14: warning: assignment makes pointer from integer without a cast [enabled by default]
  Linking C executable bin/xraw
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XOpenDisplay'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCloseDisplay'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCreateColormap'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCreateWindow'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XMapWindow'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'glXCreateContextAttribsARB'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function Cleanup: error: undefined reference to 'XDestroyWindow'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function Cleanup: error: undefined reference to 'XCloseDisplay'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function main: error: undefined reference to 'XNextEvent'
  CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function main: error: undefined reference to 'XGetWindowAttributes'
  collect2: error: ld returned 1 exit status
  make[2]: *** [bin/xraw] Errore 1
  make[1]: *** [CMakeFiles/xraw.dir/all] Errore 2
  make: *** [all] Errore 2
  </code></pre>
  
  <p>Now, I've tried to search the web and even here on SO.com for solutions, but they keep telling me to link the libraries I've already added to the linking phase.. so I can't seem to make any more progress.</p>
  
  <p>Do you happen to have some knowledge or hint that could help me?</p>
  
  <hr>
  
  <p>Ok, stimulated by answers I've gone into CMakeFiles directory and looked for the configuration file that manages the compilation. I've found out that for some reasons it did miss some of the flags stated into the CMakeLists despite of my update.</p>
  
  <p>So now the compilation line looks like:</p>
  
  <pre><code>/usr/bin/cc      CMakeFiles/xraw.dir/src/xraw/xraw.c.o  -o bin/xraw  -L/opt/sb6code/lib -rdynamic -lGL -lglut -lGLU -lm -lX11 -ldl -lGLEW -lXrandr -lXext -lrt -lglfw -Wl,-rpath,/opt/sb6code/lib 
  </code></pre>
  
  <p>And the errors have reduced to : </p>
  
  <pre><code>CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'glXCreateContextAttribsARB'
  collect2: error: ld returned 1 exit status
  make[2]: *** [bin/xraw] Errore 1
  make[1]: *** [CMakeFiles/xraw.dir/all] Errore 2
  make: *** [all] Errore 2
  </code></pre>
  
  <p>Other hints? :)</p>
  
  <p>Side Note:
  I've also installed CUDA libraries and under path</p>
  
  <pre><code>/usr/lib/nvidia-304/
  </code></pre>
  
  <p>I happen to have </p>
  
  <pre><code>alt_ld.so.conf                libnvidia-ml.so.1
  bin/                          libnvidia-ml.so.304.88
  ld.so.conf                    libnvidia-opencl.so.1
  libcuda.so                    libnvidia-opencl.so.304.88
  libcuda.so.1                  libnvidia-tls.so.304.88
  libcuda.so.304.88             libnvidia-wfb.so.1
  libGL.so                      libnvidia-wfb.so.304.88
  libGL.so.1                    libOpenCL.so
  libGL.so.304.88               libOpenCL.so.1
  libnvcuvid.so                 libOpenCL.so.1.0
  libnvcuvid.so.1               libOpenCL.so.1.0.0
  libnvcuvid.so.304.88          libXvMCNVIDIA_dynamic.so.1
  libnvidia-cfg.so              libXvMCNVIDIA.so
  libnvidia-cfg.so.1            libXvMCNVIDIA.so.1
  libnvidia-cfg.so.304.88       libXvMCNVIDIA.so.304.88
  libnvidia-compiler.so         tls/
  libnvidia-compiler.so.1       vdpau/
  libnvidia-compiler.so.304.88  xorg/
  libnvidia-glcore.so.304.88    XvMCConfig
  libnvidia-ml.so  
  </code></pre>
  
  <p>Which I would like to use since I'm not sure that my intel graphic card supports OpenGl 4.* which I shall use with the book, while the nvidia one supports 4.2.</p>
  
  <p>I really can't find any good how to on the matter, the Book conveniently avoids to give installation instructions.</p>
  
  <hr>
  
  <p>Temporary Solution:
  I've found out that this is the only source file that does not work. Removing its files and CMakeList.txt configuration seems to be wise until someone finds out another solution.</p>
  
  <p>Also, i had to use optirun to run the executables, in case other people with bumblebee/nvidia are wondering why their programs do not work.</p>