Reputation: 456
I'm trying to add the glew and glut flags to my cmd line to properly compile my program.
Code without GLEW and GLUT:
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdio.h>
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;
}
Running this with this command:
g++ openGL.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework
IOKit -framework CoreVideo
works and draws a triangle. Adding in the include glew and glut statements:
#include <GL/glew.h>
#include <GL/glut.h>
and using this command instead:
g++ openGL.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework
IOKit -framework CoreVideo -lglut -lGLU -lGL -lGLEW
causes the compiler to give over 20 errors and give up.
Complete error message:
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.
I'm trying to learn OpenGL and have no idea what to do.
Upvotes: 2
Views: 2170
Reputation: 890
GLEW must be included before GLFW.
You need to change the include order of GLFW and GLEW to be:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
This evil is stated in the error:
/usr/local/include/GL/glew.h:85:2: error: gl.h included before glew.h
Upvotes: 0
Reputation: 2291
Glut and GLFW are completely different libraries. see here What is the difference between FreeGLUT vs GLFW?
I don't believe its advisable to try to mix them in the same program and the .h files may clash - which probably explains many of the errors.
Normally you can use GLFW or GLUT but not both and they behave quite differently.
Also I notice you are using Immediate Mode to draw in OpenGL. This is easy and not a bad place to start, but is not done like this anymore. So be prepared for a more complicated but vastly faster and more powerful way to draw using Vertex Array objects (VBO). While you are doing Immediate Mode, try to read ahead and do some VBO tutorials.
Upvotes: 3