title: Compiling Multiple C++ OpenGL
body: <p>I'm writing a simple C++, opengl program and I'm having difficulty producing the executable from the object files. I can create object files of each .cpp without error using:</p>
  
  <pre><code>g++ -c filename.cpp  ----&gt;   filename.o
  </code></pre>
  
  <p>Each .cpp creates an object, which leads me to assume that it is finding the opengl headers fine, but when I attempt to create the executable from the objects, it outputs:</p>
  
  <pre><code>g++ -o OUTPUT Main.o Time.o Map.o Vehicle.o
  
  Main.o: In function `init()':
  Main.cpp:(.text+0x12a): undefined reference to `glEnable'
  Main.cpp:(.text+0x134): undefined reference to `glShadeModel'
  Main.cpp:(.text+0x14d): undefined reference to `glViewport'
  Main.cpp:(.text+0x157): undefined reference to `glMatrixMode'
  Main.cpp:(.text+0x15c): undefined reference to `glLoadIdentity'
  </code></pre>
  
  <p>I realize that the g++ is telling me that it can't find the OpenGL functions anywhere, which means it is not linking to glu.h, gl.h etc. But why do the objects files get created without similar error, but I can't make my executable? Wouldn't the object files suffer from the same linking error as the .exe? I've tried -I and g++ -o RUN Time.o Main.o Map.o Vehicle.o -L/usr/include/GL/ -lGL -lGLU, and I've also verified the path of the OpenGL directory.</p>
  
  <p>The headers of each files are below:</p>
  
  <p>libgl.h:</p>
  
  <pre><code>#ifndef LIBGL_H
  #define LIBGL_H
  
  #include &lt;GL/gl.h&gt;
  #include &lt;GL/glu.h&gt;
  #include &lt;GL/glut.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;math.h&gt;
  #include "Time.h"
  #include "Link.h"
  
  #endif
  </code></pre>
  
  <p>Time.h:</p>
  
  <pre><code>#ifndef TIME_H
  #define TIME_H
  
  extern float GLOBAL_TIME;
  
  #endif
  </code></pre>
  
  <p>Map.h</p>
  
  <pre><code>#ifndef MAP_H
  #define MAP_H
  #include "libgl.h"
  ....
  #endif
  </code></pre>
  
  <p>Vehicle.h:</p>
  
  <pre><code>#ifndef VEHICLE_H
  #define VEHICLE_H
  #include "libgl.h"
  ...
  #endif
  </code></pre>
  
  <p>Main.cpp:</p>
  
  <pre><code>#include "libgl.h"
  #include "Map.h"
  #include "Vehicle.h"
   ...
  </code></pre>
  
  <p>There is something that I'm missing regarding my headers/linking and compiling, if anybody has any suggestions I would be much obliged. </p>