Setting up GLFW with MinGW

Hello! My name is Vince, and I’ve been trying to setup GLFW on Windows 10 with MinGW for a project of mine, I included GLFW/glfw3.h just fine, and I’ve done the linking for MinGW just fine also, however, when I try and compile my program I get an error saying that some GLFW functions aren’t defined. I don’t have access to the source right now as I’m typing this on a Chromebook, but later I will be able to give the Makefile and others. Any help is appreciated, thanks in advance,


Hi Vince,

Welcome to the GLFW forum!

Have you read the MinGW Building Applications notes?

You might find that using this Cmake GLFW Starter helpful, though I’ve not tested it with MinGW:


Thanks Doug, I’ve seen this and it didn’t do much. But here’s the makefile output if it’s any use
❯ make -f .\
g++ -Iinclude -Llib-mingw-w64 -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 Source/main.cpp Source/vlib.cpp -o dist/out.exe
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x30): undefined reference to glfwSetWindowShouldClose' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x12d): undefined reference to glfwInit’
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x165): undefined reference to glfwCreateWindow' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x175): undefined reference to glfwTerminate’
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x18b): undefined reference to glfwMakeContextCurrent' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x19e): undefined reference to glfwSetKeyCallback’
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1ac): undefined reference to __imp_glClear' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1ba): undefined reference to glfwSwapBuffers’
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1bf): undefined reference to glfwPollEvents' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1cb): undefined reference to glfwWindowShouldClose’
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1d9): undefined reference to glfwTerminate' c:/users/owner/documents/winbuilds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Owner\AppData\Local\Temp\cc0gresO.o: bad reloc address 0x18 in section .xdata’
collect2.exe: error: ld returned 1 exit status
make: *** [all] Error 1

GNU linker searches dependencies in libraries/files from command-line only left to right. So if your main.cpp depends on functions in glfw or opengl, then it must come first in command-line, not after glfw/opengl:

g++ -Iinclude -Llib-mingw-w64 Source/main.cpp -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 Source/vlib.cpp -o dist/out.exe

Alternative is to use -Wl,--start-group that will make it search dependencies in any order:

g++ -Iinclude -Llib-mingw-w64 -Wl,--start-group -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 Source/main.cpp Source/vlib.cpp -o dist/out.exe -Wl,--end-group