title: C++ GL linker undefined reference
body: <p>Using Ubuntu 14.04, g++, I want to port a project from make to cmake. Getting the following error when I <code>sudo make install</code>.</p>
  
  <pre><code>Linking CXX executable texmapper
  /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../..
  /lib/libplibssg.a(ssgLeaf.o): undefined reference to symbol 'glNewList'
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libGL.so: 
  error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>A linker error like many encountered on this website. But the usually suggested fix, <code>"-lGL -lGLU -lglut</code>, does not work. I also tried some permutations of this.</p>
  
  <p>Before the undefined reference to <code>glNewList</code> I had an undefined reference to <code>glPopClientAttrib</code>, which I solved by adding <code>lGL</code>, like this:</p>
  
  <pre><code>set(CMAKE_CXX_FLAGS "-lGL")
  </code></pre>
  
  <p>So I am on the right track, but the answer is eluding me.</p>
  
  <p>Edit: full command (verbose):</p>
  
  <pre><code>/usr/bin/c++   -lGLEW -lGL -lGLU -lglut    CMakeFiles/texmapper.dir/maintexmapper.o CMakeFiles/texmapper.dir/ssgSaveAC.o  -o texmapper -rdynamic -Wl,-Bstatic -lplibsg -lplibssg -lplibul -Wl,-Bdynamic ../../libs/tgf/libtgf.so ../../libs/tgfclient/libtgfclient.so -lglut -lXmu -lXi -lpng -lz -lSM -lICE -lX11 -lXext -lXrandr -Wl,-rpath,/home/jeroen/Thesis/torcsCMAKE/trunk/src/libs/tgf:/home/jeroen/Thesis/torcsCMAKE/trunk/src/libs/tgfclient
  </code></pre>