Linking errors in msys-mingw64

I have been developing a project using glfw on linux for a while now, and I decided to port it to windows, and I am using the default msys pacman implementation to download libraries. However, I am getting full pages of undefined references when I try to compile, but no matter what I link in, or if I try to change the libs from static to dynamic, it doesn’t seem to fix it. I will also note that this is happening with multiple libraries, but mostly glfw.

Link command:

gcc -L/mingw64/lib -g -lgdi32 -luser32 -lwinmm -lkernel32 -lglfw3 -lm -lopengl32 -lopenal -lglew32 -llibconfig -o bin/program obj/Audio.o obj/Camera.o obj/Config.o obj/Files.o obj/Input.o obj/Main.o obj/Models.o obj/Physics.o obj/Renderer.o obj/Shader.o obj/Texture.o obj/Util.o obj/WindowManager.o

Errors:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\biscu\Desktop\gtma-master/src/Input.c:134:(.text+0x307): undefined reference to `glfwSetCursorPosCallback'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\biscu\Desktop\gtma-master/src/Input.c:135:(.text+0x31e): undefined reference to `glfwSetMouseButtonCallback'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\biscu\Desktop\gtma-master/src/Input.c:136:(.text+0x335): undefined reference to `glfwSetWindowSizeCallback'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\biscu\Desktop\gtma-master/src/Input.c:137:(.text+0x34c): undefined reference to `glfwSetWindowPosCallback'

I am not well versed in developing on windows, so it might be something super simple that I am not seeing, but any help would still be appreciated.

1 Like

I would check out the documentation on building applications with GLFW with MinGW-w64 and GLFW binaries or if you are OK with using CMake check out the GLFW CMake Starter.

What worked for me when I tried porting to Windows is to change the order linked libraries are mentioned. In your case, linking doesn’t work because the linker doesn’t “see” the GLFW library. Assuming libraries are in /mingw64/lib something like this should work:

gcc -L/mingw64/lib -g -lglfw3 -lopengl32 -lopenal ...

In other words, the order you link libraries does matter on some systems (Windows/mingw64 is one of them). In general, this is not true in most GNU/Linux systems, but I have also seen a few distributions where you have to do something similar, otherwise linking fails.