title: Undefined References Compiling OpenGL/glfw/glew on Ubuntu(g++)
body: <p>I am following <a href="http://learnopengl.com/#!Getting-started/Creating-a-window">this tutorial</a>. I <code>cmake'd</code> and <code>make/make install'd</code> <code>glfw</code> and <code>glew</code> perfectly(as far as I'm aware). However, when I try to compile the sample code...</p>
  
  <pre><code>#define GLEW_STATIC
  #include &lt;GL/glew.h&gt;
  #include &lt;GLFW/glfw3.h&gt;
  
  int main()
  {
      glfwInit();
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  
      return 0;
  }
  </code></pre>
  
  <p>... using his linker flags...</p>
  
  <pre><code>-lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi
  </code></pre>
  
  <p>... I get the following error:</p>
  
  <pre><code>/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_init.c.o): undefined reference to symbol 'XF86VidModeQueryExtension'
  /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1: error adding symbols: DSO missing from command line
  </code></pre>
  
  <p>I Google'd the error and someone suggested adding <code>-lXxf86vm</code>. It got rid of the initial error but added a significant number more:</p>
  
  <pre><code>/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
  x11_init.c:(.text+0x1b93): undefined reference to `XineramaQueryExtension'
  x11_init.c:(.text+0x1bad): undefined reference to `XineramaIsActive'
  /usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor':
  x11_init.c:(.text+0x22ee): undefined reference to `XcursorImageCreate'
  x11_init.c:(.text+0x23c5): undefined reference to `XcursorImageLoadCursor'
  x11_init.c:(.text+0x23d5): undefined reference to `XcursorImageDestroy'
  /usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
  x11_monitor.c:(.text+0x743): undefined reference to `XineramaQueryScreens'
  </code></pre>
  
  <p>How do I figure out what flags I need? If it matters this is how my makefile is structured:</p>
  
  <pre><code>CC = g++
  COMPILER_FLAGS = -std=c++11
  FILES = *.cpp
  LINKER_FLAGS =   -lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -lXxf86vm
  OBJS = *.o
  LINUX_BIN = HelloWindow
  
  #Compile(output into error.txt if there is an error), link, then run
  linux:
      $(CC) $(COMPILER_FLAGS) -c $(FILES) 2&gt; "errors.txt"
      $(CC) $(COMPILER_FLAGS) $(OBJS) -o $(LINUX_BIN) $(LINKER_FLAGS)
      ./$(LINUX_BIN)        
  </code></pre>
  
  <p>Thanks!</p>