Linking libglfw3.a undefined reference

Hi guys,
i have just downloaded the sources for glfw-3.3.8 and used cmake and mingw32-make to compile the sources. So far so good.

But when i try to link the /build/src/libglfw3.a file like that:

g++ test.cpp C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a -o test

and then call any function, i get the following output in the terminal:

C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x175): undefined reference to `__imp_CreateDCW'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x1ad): undefined reference to `__imp_GetDeviceCaps'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x1cb): undefined reference to `__imp_GetDeviceCaps'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x22b): undefined reference to `__imp_GetDeviceCaps'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x29c): undefined reference to `__imp_GetDeviceCaps'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x2c8): undefined reference to `__imp_DeleteDC'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0xc75): undefined reference to `__imp_GetDeviceCaps'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0xc8d): undefined reference to `__imp_GetDeviceCaps'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x12c1): undefined reference to `__imp_CreateDCW'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x12df): undefined reference to `__imp_GetDeviceGammaRamp'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x12f2): undefined reference to `__imp_DeleteDC'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x1451): undefined reference to `__imp_CreateDCW'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x146f): undefined reference to `__imp_SetDeviceGammaRamp'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_monitor.c.obj):win32_monitor.:(.text+0x1482): undefined reference to `__imp_DeleteDC'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x232): undefined reference to `__imp_CreateDIBSection'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x2a3): undefined reference to `__imp_CreateBitmap'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x2d2): undefined reference to `__imp_DeleteObject'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x3da): undefined reference to `__imp_DeleteObject'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x3ea): undefined reference to `__imp_DeleteObject'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xc81): undefined reference to `__imp_CreateRectRgn'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xce6): undefined reference to `__imp_DeleteObject'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x8fb): undefined reference to `__imp_DescribePixelFormat'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xe24): undefined reference to `__imp_DescribePixelFormat'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1234): undefined reference to `__imp_SwapBuffers'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1673): undefined reference to `__imp_ChoosePixelFormat'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x168c): undefined reference to `__imp_SetPixelFormat'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1b28): undefined reference to `__imp_DescribePixelFormat'
C:/Program Files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1b6e): undefined reference to `__imp_SetPixelFormat'
collect2.exe: error: ld returned 1 exit status

See the guide on building applications with MinGW, in particular the line:

When using MinGW to link an application with the static version of GLFW, you must also explicitly link with gdi32. Other toolchains including MinGW-w64 include it in the set of default libraries along with other dependencies like user32 and kernel32.

So you should write (note this is untested):

g++ test.cpp C:\git\opengl\glfw-3.3.8\glfw-3.3.8\build\src\libglfw3.a -lgdi32 -o test

thanks, that did the trick!
meanwhile i have also found out that linking the dll and not the .a does also work.

For everybody wondering, to get the dll from the sources, you need to call cmake with
-D BUILD_SHARED=ON