GLFW doesn't seem to be linking properly with MinGW-w64

Hello all,
I’m new to both OpenGL and CMake, and am trying to get GLFW working with MinGW-w64, intending to link the library dynamically. I downloaded 64-bit GLFW and simply copy-pasted the GLFW folder in the include folder to MinGW’s include directory (mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\include) as well as the contents of the lib-mingw-w64 folder to MinGW’s lib directory (mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\bin).

And of course, upon running the example code, I get linker errors I’m too new to understand:

undefined reference to glfwInit' undefined reference to glfwCreateWindow’
undefined reference to glfwTerminate' undefined reference to glfwMakeContextCurrent’
undefined reference to glfwWindowShouldClose' undefined reference to _imp__glClear@4’
undefined reference to glfwSwapBuffers' undefined reference to glfwPollEvents’
undefined reference to `glfwTerminate’

I actually have no idea what extra steps I need to take, and whether or not I need to add new lines in CMakeLists.txt or download/include additional libraries/binaries. Any help is appreciated, as I’m completely new to the whole thing. There doesn’t seem to be very many online tutorials either.

Also, if it’s relevant at all, I’m using CLion as my IDE.

Hi RapidFruity,

Welcome to the GLFW forums!

Using MinGW is somewhat complicated, so I would only recommend this to advanced developers over using the free Visual Studio Community compiler & IDE, or the cross platform Visual Studio Code C/C++.

Your error is due to not linking the GLFW library - see the GLFW documentation on building applications with MinGW. I don’t now how to add the a library to your configuration for CLion, but if you search I’m sure you can find the answer.

Alternatively you could try the GFLW CMake Starter, though I’ve not tried this with MinGW.



1 Like