title: OpengGL makefile linker error in c++
body: <p>I been trying to make Makefile for medium sized project but it is no go for me:</p>
  
  <pre><code>DPS=-Wall -lglfw -lGLEW
  main: glfw.o shader.o
      g++ $(DPS) glfw.o shader.o -o main.run
  
  glfw.o: glfw.cpp
      g++ $(DPS) -c glfw.cpp
  
  shader.o: shader.cpp shader.h
      g++ $(DPS) -c shader.cpp
  
  clear:
      rm *.o main.run
  </code></pre>
  
  <p>When i run make it throws up:</p>
  
  <pre><code>g++ -Wall -lglfw -lGLEW -c glfw.cpp
  glfw.cpp: In function ‘int main()’:
  glfw.cpp:48:17: warning: unused variable ‘EBO’ [-Wunused-variable]
    GLuint VBO,VAO,EBO;
                   ^
  g++ -Wall -lglfw -lGLEW -c shader.cpp
  g++ -Wall -lglfw -lGLEW glfw.o shader.o -o main.run
  glfw.o: In function `main':
  glfw.cpp:(.text+0x1c): undefined reference to `glfwInit'
  glfw.cpp:(.text+0x3e): undefined reference to `glfwWindowHint'
  glfw.cpp:(.text+0x4d): undefined reference to `glfwWindowHint'
  glfw.cpp:(.text+0x5c): undefined reference to `glfwWindowHint'
  glfw.cpp:(.text+0x6b): undefined reference to `glfwWindowHint'
  glfw.cpp:(.text+0x8a): undefined reference to `glfwCreateWindow'
  glfw.cpp:(.text+0xb6): undefined reference to `glfwTerminate'
  glfw.cpp:(.text+0xcc): undefined reference to `glfwMakeContextCurrent'
  glfw.cpp:(.text+0xd1): undefined reference to `glfwGetVersionString'
  glfw.cpp:(.text+0x105): undefined reference to `glewGetString'
  glfw.cpp:(.text+0x139): undefined reference to `glGetString'
  glfw.cpp:(.text+0x16d): undefined reference to `glGetString'
  glfw.cpp:(.text+0x1a1): undefined reference to `glGetString'
  glfw.cpp:(.text+0x1d5): undefined reference to `glGetString'
  glfw.cpp:(.text+0x205): undefined reference to `glewExperimental'
  glfw.cpp:(.text+0x20b): undefined reference to `glewInit'
  glfw.cpp:(.text+0x23a): undefined reference to `glewGetErrorString'
  glfw.cpp:(.text+0x34f): undefined reference to `__glewGenVertexArrays'
  glfw.cpp:(.text+0x364): undefined reference to `__glewBindVertexArray'
  glfw.cpp:(.text+0x372): undefined reference to `__glewGenBuffers'
  glfw.cpp:(.text+0x38a): undefined reference to `__glewBindBuffer'
  glfw.cpp:(.text+0x3a0): undefined reference to `__glewBufferData'
  glfw.cpp:(.text+0x3bc): undefined reference to `__glewEnableVertexAttribArray'
  glfw.cpp:(.text+0x3ca): undefined reference to `__glewVertexAttribPointer'
  glfw.cpp:(.text+0x402): undefined reference to `glfwWindowShouldClose'
  glfw.cpp:(.text+0x420): undefined reference to `glClearColor'
  glfw.cpp:(.text+0x42a): undefined reference to `glClear'
  glfw.cpp:(.text+0x436): undefined reference to `glfwSwapBuffers'
  glfw.cpp:(.text+0x43b): undefined reference to `glfwPollEvents'
  glfw.cpp:(.text+0x442): undefined reference to `glfwTerminate'
  shader.o: In function `BasicShader::BasicShader(char const*, char const*)':
  shader.cpp:(.text+0xa4): undefined reference to `__glewCreateShader'
  shader.cpp:(.text+0x16c): undefined reference to `__glewShaderSource'
  shader.cpp:(.text+0x18c): undefined reference to `__glewCompileShader'
  shader.cpp:(.text+0x19d): undefined reference to `__glewGetShaderiv'
  shader.cpp:(.text+0x32c): undefined reference to `__glewCreateShader'
  shader.cpp:(.text+0x340): undefined reference to `__glewShaderSource'
  shader.cpp:(.text+0x360): undefined reference to `__glewCompileShader'
  shader.cpp:(.text+0x371): undefined reference to `__glewCreateProgram'
  shader.cpp:(.text+0x385): undefined reference to `__glewAttachShader'
  shader.cpp:(.text+0x3a1): undefined reference to `__glewAttachShader'
  shader.cpp:(.text+0x3bd): undefined reference to `__glewLinkProgram'
  shader.o: In function `BasicShader::use()':
  shader.cpp:(.text+0x533): undefined reference to `__glewUseProgram'
  shader.o: In function `BasicShader::setBool(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, bool) const':
  shader.cpp:(.text+0x55d): undefined reference to `__glewGetUniformLocation'
  shader.cpp:(.text+0x583): undefined reference to `__glewUniform1i'
  shader.o: In function `BasicShader::setInt(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, int) const':
  shader.cpp:(.text+0x5b3): undefined reference to `__glewGetUniformLocation'
  shader.cpp:(.text+0x5d9): undefined reference to `__glewUniform1i'
  shader.o: In function `BasicShader::setFloat(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, float) const':
  shader.cpp:(.text+0x60b): undefined reference to `__glewGetUniformLocation'
  shader.cpp:(.text+0x631): undefined reference to `__glewUniform1f'
  collect2: error: ld returned 1 exit status
  Makefile:4: recipe for target 'main' failed
  make: *** [main] Error 1
  </code></pre>
  
  <p>This is main file:</p>
  
  <pre><code>#include "shader.h"
  #include &lt;GLFW/glfw3.h&gt;
  
  //int main( int argc, char** argv)
  int main()
  {
  
      if( !glfwInit() )
          return -1;
  
      glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
      glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 );
      glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
      glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
  
      GLFWwindow* window = glfwCreateWindow( 640, 480, "&lt;++&gt;", NULL, NULL );
      if( !window )
      {
          std::cerr &lt;&lt; "Error on window creating" &lt;&lt; std::endl;
          glfwTerminate();
          return -1;
      }
  
      glfwMakeContextCurrent( window );
  
      std::cout &lt;&lt; "GLFW version                : " &lt;&lt; glfwGetVersionString() &lt;&lt; std::endl;
      std::cout &lt;&lt; "GLEW_VERSION                : " &lt;&lt; glewGetString( GLEW_VERSION ) &lt;&lt; std::endl;
      std::cout &lt;&lt; "GL_VERSION                  : " &lt;&lt; glGetString( GL_VERSION ) &lt;&lt; std::endl;
      std::cout &lt;&lt; "GL_VENDOR                   : " &lt;&lt; glGetString( GL_VENDOR ) &lt;&lt; std::endl;
      std::cout &lt;&lt; "GL_RENDERER                 : " &lt;&lt; glGetString( GL_RENDERER ) &lt;&lt; std::endl;
      std::cout &lt;&lt; "GL_SHADING_LANGUAGE_VERSION : " &lt;&lt; glGetString( GL_SHADING_LANGUAGE_VERSION ) &lt;&lt; std::endl;
  
      glewExperimental = true;
      GLenum err = glewInit();
      if( err!= GLEW_OK )
      {
          std::cerr &lt;&lt; "Glew init failed!" &lt;&lt; std::endl;
          std::cerr &lt;&lt; "Error: " &lt;&lt; glewGetErrorString( err ) &lt;&lt; std::endl;
      }
  
      GLfloat vertices[] = { -0.75,-0.75,0,0,0,
          -0.75,0.75,0,0,1,
          0.75,0.75,0,1,1,
          0.75,-0.75,0,1,0
      };
  
  
      GLuint VBO,VAO,EBO;
  
      glGenVertexArrays(1,&amp;VAO);
      glBindVertexArray(VAO);
  
      glGenBuffers(1,&amp;VBO);
      glBindBuffer(GL_ARRAY_BUFFER,VBO);
      glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);
  
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(void*)0);
  
  
  
  
      while( !glfwWindowShouldClose(window) )
      {
          glClearColor( 0, 0, 0, 0 );
          glClear( GL_COLOR_BUFFER_BIT );
  
  
  
          glfwSwapBuffers( window );
  
          glfwPollEvents();
      }
  
      glfwTerminate();
      return 0;
  }
  </code></pre>
  
  <p>Shader.h:</p>
  
  <pre><code>#ifndef SHADER_H
  #define SHADER_H
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstring&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #define GLEW_STATIC
  #include &lt;GL/glew.h&gt;
  
  
  
  class BasicShader
  {
      public:
      unsigned int ID;
      BasicShader(const char* vShader,const char* fShader);
  
      void use();
  
      void setBool(const std::string &amp;name,bool value) const;
      void setInt(const std::string &amp;name,int value) const;
      void setFloat(const std::string &amp;name,float value) const;
  };
  
  #endif
  </code></pre>
  
  <p>Shader.cpp:</p>
  
  <pre><code>#include "shader.h"
  
  BasicShader::BasicShader(const char* vShader,const char* fShader)
  {
      std::fstream vPath(vShader, std::ios::in);
      std::ostringstream vStream;
  
      if (vPath.fail())
      {
          std::cout &lt;&lt; "BASICSHADER::VERTEX::FAILED_TO_OPEN" &lt;&lt; std::endl;
      }
  
      unsigned int vShaderID = 0;
      vShaderID = glCreateShader(GL_VERTEX_SHADER);
  
      std::string vShaderString = "";
      vStream &lt;&lt; vPath.rdbuf();
  
      vShaderString = vStream.str();
  
      const char* vShaderSource = vShaderString.c_str();
  
      glShaderSource(vShaderID,1,&amp;vShaderSource,NULL);
      glCompileShader(vShaderID);
  
      #ifndef DEBUG_MODE
      int success;
      char infoLog[1024];
      glGetShaderiv(vShaderID, GL_COMPILE_STATUS, &amp;success);
      if (!success)
      {
          std::cout &lt;&lt; "BASICSHADER::VERTEX::FAILED_TO_COMPILE\n" &lt;&lt; infoLog &lt;&lt; std::endl;
      }
      #endif
  
      unsigned int fShaderID = 0;
      std::fstream fPath(fShader,std::ios::in);
  
      if (fPath.fail())
      {
          std::cout &lt;&lt; "BASICSHADER::FRAGMENT::FAILED_TO_OPEN" &lt;&lt; std::endl;
      } 
  
      std::string fShaderString = "";
      std::stringstream fSteam;
      fSteam &lt;&lt; fPath.rdbuf();
      fShaderString = fSteam.str();
  
  
      const char* fShaderSource = fShaderString.c_str();
  
      fShaderID = glCreateShader(GL_FRAGMENT_SHADER);
      glShaderSource(fShaderID,1,&amp;fShaderSource,NULL);
      glCompileShader(fShaderID);
  
      #ifdef DEBUG_MODE
      glGetShaderiv(vShaderID, GL_COMPILE_STATUS, &amp;success);
      if (!success)
      {
          std::cout &lt;&lt; "BASICSHADER::FRAGMENT::FAILED_TO_COMPILE\n" &lt;&lt; infoLog &lt;&lt; std::endl;
      }
      #endif
  
      ID = glCreateProgram();
      glAttachShader(ID,vShaderID);
      glAttachShader(ID,fShaderID);
      glLinkProgram(ID);
  
      #ifdef DEBUG_MODE
      glGetProgramiv(ID, GL_LINK_STATUS, &amp;success);
      if(!success) {
      glGetProgramInfoLog(ID, 1024, NULL, infoLog);
      std::cout &lt;&lt; "BASICSHADER::PROGRAM::ID::FAILED_TO_LINK\n" &lt;&lt; infoLog &lt;&lt; std::endl;
  
      }
      #endif
  }
  
      void BasicShader::use()
  {
      glUseProgram(ID);
  }
  
      void BasicShader::setBool(const std::string &amp;name,bool value) const
  {
      int uniformLoc = glGetUniformLocation(ID,name.c_str());
      glUniform1i(uniformLoc,static_cast&lt;int&gt;(value));
  }
  
      void BasicShader::setInt(const std::string &amp;name,int value) const
  {
      int uniformLoc = glGetUniformLocation(ID,name.c_str());
      glUniform1i(uniformLoc,value);
  }
  
  
      void BasicShader::setFloat(const std::string &amp;name,float value) const
  {
      int uniformLoc = glGetUniformLocation(ID,name.c_str());
      glUniform1f(uniformLoc,value);
  }
  </code></pre>