title: Compile GLEW and GLUT on macOS?
body: <p>I'm trying to add the glew and glut flags to my cmd line to properly compile my program.</p>
  
  <p>Code without GLEW and GLUT:</p>
  
  <pre><code>#include &lt;GLFW/glfw3.h&gt;
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  int main(void)
  {
      GLFWwindow* window;
  
      /* Initialize the library */
      if (!glfwInit())
      return -1;
  
      /* Create a windowed mode window and its OpenGL context */
      window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
      if (!window)
      {
          glfwTerminate();
          return -1;
      }
  
      /* Make the window's context current */
      glfwMakeContextCurrent(window);
  
      /* Loop until the user closes the window */
      while (!glfwWindowShouldClose(window))
      {
      /* Render here */
          glClear(GL_COLOR_BUFFER_BIT);
          glBegin(GL_TRIANGLES);
          glVertex2f(-0.5f, -0.5f);
          glVertex2f(0.0f, 0.5f);
          glVertex2f(0.5f, -0.5f);
          glEnd();
  
          /* Swap front and back buffers */
          glfwSwapBuffers(window);
  
          /* Poll for and process events */
          glfwPollEvents();
      }
  
      glfwTerminate();
      return 0;
  
  }
  </code></pre>
  
  <p>Running this with this command:</p>
  
  <pre><code>g++ openGL.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework 
  IOKit -framework CoreVideo
  </code></pre>
  
  <p>works and draws a triangle. Adding in the include glew and glut statements:</p>
  
  <pre><code>#include &lt;GL/glew.h&gt;
  #include &lt;GL/glut.h&gt;
  </code></pre>
  
  <p>and using this command instead:</p>
  
  <pre><code>g++ openGL.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework 
  IOKit -framework CoreVideo -lglut -lGLU -lGL -lGLEW
  </code></pre>
  
  <p>causes the compiler to give over 20 errors and give up.</p>
  
  <p>Complete error message:</p>
  
  <pre><code>In file included from openGL.cpp:9:
  In file included from ./openGL.hpp:12:
  /usr/local/include/GL/glew.h:85:2: error: gl.h included before glew.h
  #error gl.h included before glew.h
   ^
  /usr/local/include/GL/glew.h:91:2: error: gltypes.h included before glew.h
  #error gltypes.h included before glew.h
   ^
  /usr/local/include/GL/glew.h:6586:22: error: typedef redefinition with different
        types ('unsigned int' vs 'void *')
  typedef unsigned int GLhandleARB;
                       ^
  /System/Library/Frameworks/OpenGL.framework/Headers/gltypes.h:28:18: note: 
        previous definition is here
  typedef void    *GLhandleARB;
                   ^
  In file included from openGL.cpp:9:
  In file included from ./openGL.hpp:12:
  /usr/local/include/GL/glew.h:19860:17: error: unknown type name
        'PFNGLCOPYTEXSUBIMAGE3DPROC'; did you mean 'PFNGLCOPYTEXSUBIMAGE3DNVPROC'?
  GLEW_FUN_EXPORT PFNGLCOPYTEXSUBIMAGE3DPROC __glewCopyTexSubImage3D;
                  ^
  /usr/local/include/GL/glew.h:16452:28: note: 'PFNGLCOPYTEXSUBIMAGE3DNVPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLCOPYTEXSUBIMAGE3DNVPROC) (GLenum target...
                             ^
  /usr/local/include/GL/glew.h:19861:17: error: unknown type name
        'PFNGLDRAWRANGEELEMENTSPROC'; did you mean
        'PFNGLDRAWRANGEELEMENTSEXTPROC'?
  GLEW_FUN_EXPORT PFNGLDRAWRANGEELEMENTSPROC __glewDrawRangeElements;
                  ^
  /usr/local/include/GL/glew.h:10251:28: note: 'PFNGLDRAWRANGEELEMENTSEXTPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, ...
                             ^
  /usr/local/include/GL/glew.h:19862:17: error: unknown type name
        'PFNGLTEXIMAGE3DPROC'; did you mean 'PFNGLTEXIMAGE3DNVPROC'?
  GLEW_FUN_EXPORT PFNGLTEXIMAGE3DPROC __glewTexImage3D;
                  ^
  /usr/local/include/GL/glew.h:16454:28: note: 'PFNGLTEXIMAGE3DNVPROC' declared
        here
  typedef void (GLAPIENTRY * PFNGLTEXIMAGE3DNVPROC) (GLenum target, GLint ...
                             ^
  /usr/local/include/GL/glew.h:19863:17: error: unknown type name
        'PFNGLTEXSUBIMAGE3DPROC'; did you mean 'PFNGLTEXSUBIMAGE3DNVPROC'?
  GLEW_FUN_EXPORT PFNGLTEXSUBIMAGE3DPROC __glewTexSubImage3D;
                  ^
  /usr/local/include/GL/glew.h:16455:28: note: 'PFNGLTEXSUBIMAGE3DNVPROC' declared
        here
  typedef void (GLAPIENTRY * PFNGLTEXSUBIMAGE3DNVPROC) (GLenum target, GLi...
                             ^
  /usr/local/include/GL/glew.h:19865:17: error: unknown type name
        'PFNGLACTIVETEXTUREPROC'; did you mean 'PFNGLACTIVETEXTUREARBPROC'?
  GLEW_FUN_EXPORT PFNGLACTIVETEXTUREPROC __glewActiveTexture;
                  ^
  /usr/local/include/GL/glew.h:5701:28: note: 'PFNGLACTIVETEXTUREARBPROC' declared
        here
  typedef void (GLAPIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
                             ^
  /usr/local/include/GL/glew.h:19866:17: error: unknown type name
        'PFNGLCLIENTACTIVETEXTUREPROC'; did you mean
        'PFNGLCLIENTACTIVETEXTUREARBPROC'?
  GLEW_FUN_EXPORT PFNGLCLIENTACTIVETEXTUREPROC __glewClientActiveTexture;
                  ^
  /usr/local/include/GL/glew.h:5702:28: note: 'PFNGLCLIENTACTIVETEXTUREARBPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture);
                             ^
  /usr/local/include/GL/glew.h:19867:17: error: unknown type name
        'PFNGLCOMPRESSEDTEXIMAGE1DPROC'
  GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXIMAGE1DPROC __glewCompressedTexImage1D;
                  ^
  /usr/local/include/GL/glew.h:19868:17: error: unknown type name
        'PFNGLCOMPRESSEDTEXIMAGE2DPROC'
  GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXIMAGE2DPROC __glewCompressedTexImage2D;
                  ^
  /usr/local/include/GL/glew.h:19869:17: error: unknown type name
        'PFNGLCOMPRESSEDTEXIMAGE3DPROC'; did you mean
        'PFNGLCOMPRESSEDTEXIMAGE3DNVPROC'?
  GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXIMAGE3DPROC __glewCompressedTexImage3D;
                  ^
  /usr/local/include/GL/glew.h:16450:28: note: 'PFNGLCOMPRESSEDTEXIMAGE3DNVPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLCOMPRESSEDTEXIMAGE3DNVPROC) (GLenum targ...
                             ^
  /usr/local/include/GL/glew.h:19870:17: error: unknown type name
        'PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC'
  GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC __glewCompressedTexSubImage1D;
                  ^
  /usr/local/include/GL/glew.h:19871:17: error: unknown type name
        'PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC'
  GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC __glewCompressedTexSubImage2D;
                  ^
  /usr/local/include/GL/glew.h:19872:17: error: unknown type name
        'PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC'; did you mean
        'PFNGLCOMPRESSEDTEXSUBIMAGE3DNVPROC'?
  GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC __glewCompressedTexSubImage3D;
                  ^
  /usr/local/include/GL/glew.h:16451:28: note: 
        'PFNGLCOMPRESSEDTEXSUBIMAGE3DNVPROC' declared here
  typedef void (GLAPIENTRY * PFNGLCOMPRESSEDTEXSUBIMAGE3DNVPROC) (GLenum t...
                             ^
  /usr/local/include/GL/glew.h:19873:17: error: unknown type name
        'PFNGLGETCOMPRESSEDTEXIMAGEPROC'; did you mean
        'PFNGLGETNCOMPRESSEDTEXIMAGEPROC'?
  GLEW_FUN_EXPORT PFNGLGETCOMPRESSEDTEXIMAGEPROC __glewGetCompressedTexImage;
                  ^
  /usr/local/include/GL/glew.h:2486:28: note: 'PFNGLGETNCOMPRESSEDTEXIMAGEPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLGETNCOMPRESSEDTEXIMAGEPROC) (GLenum targ...
                             ^
  /usr/local/include/GL/glew.h:19874:17: error: unknown type name
        'PFNGLLOADTRANSPOSEMATRIXDPROC'; did you mean
        'PFNGLLOADTRANSPOSEMATRIXDARBPROC'?
  GLEW_FUN_EXPORT PFNGLLOADTRANSPOSEMATRIXDPROC __glewLoadTransposeMatrixd;
                  ^
  /usr/local/include/GL/glew.h:7683:28: note: 'PFNGLLOADTRANSPOSEMATRIXDARBPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLLOADTRANSPOSEMATRIXDARBPROC) (GLdouble m[16]);
                             ^
  /usr/local/include/GL/glew.h:19875:17: error: unknown type name
        'PFNGLLOADTRANSPOSEMATRIXFPROC'; did you mean
        'PFNGLLOADTRANSPOSEMATRIXFARBPROC'?
  GLEW_FUN_EXPORT PFNGLLOADTRANSPOSEMATRIXFPROC __glewLoadTransposeMatrixf;
                  ^
  /usr/local/include/GL/glew.h:7684:28: note: 'PFNGLLOADTRANSPOSEMATRIXFARBPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLLOADTRANSPOSEMATRIXFARBPROC) (GLfloat m[16]);
                             ^
  /usr/local/include/GL/glew.h:19876:17: error: unknown type name
        'PFNGLMULTTRANSPOSEMATRIXDPROC'; did you mean
        'PFNGLMULTTRANSPOSEMATRIXDARBPROC'?
  GLEW_FUN_EXPORT PFNGLMULTTRANSPOSEMATRIXDPROC __glewMultTransposeMatrixd;
                  ^
  /usr/local/include/GL/glew.h:7685:28: note: 'PFNGLMULTTRANSPOSEMATRIXDARBPROC'
        declared here
  typedef void (GLAPIENTRY * PFNGLMULTTRANSPOSEMATRIXDARBPROC) (GLdouble m[16]);
                             ^
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
  20 errors generated.
  </code></pre>
  
  <p>I'm trying to learn OpenGL and have no idea what to do.</p>