Joe Hesketh
Joe Hesketh

Reputation: 65

Linking GLEW libraries when compiling with MinGW

I'm trying to write an OpenGL program which I'm compiling through MinGW. I've managed to successfully link OpenGL, GLUT, GLFW and GLM to my main.cpp file. Given the following headers:

#include "GL/glut.h"
#include "GLFW/glfw3.h"
#include "GL/glew.h"
#include "glm/vec3.hpp"

And the following cmd line:

g++ -o leaf.exe -Wall physics.cpp -mwindows lib/glut32.lib -lopengl32 -lglu32 -lglfw3dll -lglew32 -IC:/MinGW/include/GL

I manage to get it to compile successfully. However, when placing the .a files in MinGW/lib, the .dll file in source folder and the .h file in C:\MinGW\include and adding

#include "GL/glew.h"

With the following command line

g++ -o leaf.exe -Wall physics.cpp -mwindows lib/glut32.lib -lopengl32 -lglu32 -lglfw3dll -lglew32 -IC:/MinGW/include/GL

Then I get a long list of errors including:

In file included from physics.cpp:6:0:
c:\mingw\include\gl\glew.h:85:2: error: #error gl.h included before glew.h
#error gl.h included before glew.h

In file included from physics.cpp:6:0:
c:\mingw\include\gl\glew.h:1814:94: error: 'GLchar' does not name a type
typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar* name);

My first time trying to make something without using Visual Studio or Eclipse. Been trying lots of fixes for it I've found here but nothing concrete.

Thanks for reading this far!

Upvotes: 0

Views: 2019

Answers (1)

Shokwav
Shokwav

Reputation: 664

You need to reorder your includes:

#include "GL/glew.h"
#include "GL/glut.h"
#include "GLFW/glfw3.h"
#include "glm/vec3.hpp"

GLFW (and GLUT?) automatically include GL.h, which is what GLEW is complaining about. Not sure why you're using GLUT and GLFW in the same build, they don't exactly go together...

Upvotes: 2

Related Questions