I figured it out, and for anyone ever encountering the issue I will try and make clear what exactly I did to finally be able to create OpenGL projects with the setup MinGW + GLEW + GLFW. In my case, I used Eclipse CDT as IDE, but I'll write down the resulting g++
command line so it should be easy to adapt to other IDE's.
I'll suppose MinGW and MSYS (can be chosen to be installed from within the MinGW GUI; thus no need to download separately) are installed.
Download GLFW and unzip it in your external libraries folder of choice (in my case, this is
D:\external\cpp
, so it would be something along the lines ofD:\external\cpp\glfw
, where I renamed theglfw-3.0.3.bin.WIN32
folder to simplyglfw
).Download the GLEW source as a zip folder an unzip it, in my case it's in
D:\external\cpp\glew
. Now start MSYS,cd
to theglew
folder and invokemake all
.Step 3 should have created (among others) the files
libglew32.a
andglew32.dll
inside the folderglew\lib
. Now right click your Eclipse CDT C++ project, go to Properties - C/C++ General - Paths and Symbols. In the Includes tab, add the paths to theinclude
folders of GLFW and GLEW. Again, for me this isD:\external\cpp\glew\include
and analogous for GLFW. In Library Paths, do the same for the folderslib
(GLEW) andlib-mingw
(GLFW).Now we have to add the libraries we want our project to be linked with. If you wish to link with GLEW dynamically, make sure to include the
glew32.dll
in the folder where your executable will be. In Eclipse CDT, that's usually theDebug
(orRelease
) folder in your project structure. In the Libraries tab in the options window we opened before, add (the order is important!)glfw3
,glew32
,opengl32
,glu32
,gdi32
. Now building the project should work hopefully. In case you want to link statically with GLEW, add the same libraries with the exception ofglew32
. Instead, in the project properties go to C/C++ Build - Settings and in the Tool Settings - MinGW C++ Linker - Miscellaneous tab add the path tolibglew32.a
to the Other objects field. In my case, this isD:\external\cpp\glew\lib\libglew32.a
. Now in order for the static linking to work, you have to either add#define GLEW_STATIC
above#include <GL/glew.h>
or use the preprocessor command-DGLEW_STATIC
. The GLEW homepage says that it's also possible to include theglew.c
andglew.h
files into your project in order to link statically, but somehow this didn't really work out for me.
These steps worked for me, and they produced command lines similar to the following (I have only one file named main.cpp
and used static linking with GLEW), which could be useful if you're trying to figure this matter out without Eclipse CDT.
g++ -ID:\external\cpp\glew\include -ID:\external\cpp\glfw\include -c -o main.o main.cpp
g++ -LD:\external\cpp\glew\lib -LD:\external\cpp\glfw\lib-mingw -o minimalexample.exe main.o D:\external\cpp\glew\lib\libglew32.a -lglfw3 -lopengl32 -lglu32 -lgdi32
In the dynamic linking case, simply remove the part containing libglew32.a
in the second line, and add -lglew32
between -lglfw3
and -lopengl32
. As a little example source file, you could just use the code in my above question.
I hope I can help anyone with this, as I sure saw me having a lot of trouble figuring this out between tens of error messages of unresolved symbols and various other problems :-)
Update: I tried to go over this again some days ago and ran into problems with the pre-compiled GLFW binaries for Windows (I'm now using Win8.1). But you can just use CMake in combination with mingw32-make
to compile it on your own. Also, GLEW seems to not be getting updates anymore, so I switched to glad instead. It's also possible to use MinGW-w64 to compile the libraries and your final project as 64-bit application.