My code does not compile with glfwSetWindowShouldClose()

Hi!
I’m trying to use a glfwSetWindowShouldClose() function

#include <GLFW/glfw3.h>

int main()
{
    glfwSetWindowShouldClose(nullptr, 0);
	
	return 0;
}

but it’s raising very strange errors:



H:\Projects\c\OpenGL legacy\01_OpenGL_legacy_test_minimal_render_GLFW_CodeBlocks>set compiler=g++

H:\Projects\c\OpenGL legacy\01_OpenGL_legacy_test_minimal_render_GLFW_CodeBlocks>g++ -c src\main.cpp -o obj\main.o

H:\Projects\c\OpenGL legacy\01_OpenGL_legacy_test_minimal_render_GLFW_CodeBlocks>g++ -o exe.exe obj\main.o -lopengl32 -lgdi32 -lglfw3 -LC:\MinGW\lib -IC:\MinGW\include
C:\MinGW\lib/libglfw3.a(window.c.obj):window.c:(.text+0x5da): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(window.c.obj):window.c:(.text+0xc16): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x25f): undefined reference to `CreateDIBSection@24'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x2ac): undefined reference to `CreateBitmap@20'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x34a): undefined reference to `DeleteObject@4'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x355): undefined reference to `DeleteObject@4'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x3fa): undefined reference to `DeleteObject@4'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x4c3): undefined reference to `CreateRectRgn@16'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x502): undefined reference to `DeleteObject@4'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xe51): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xe89): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xe9b): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1f85): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x2383): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x4c0c): more undefined references to `__mingw_free' follow
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x14a): undefined reference to `SwapBuffers@4'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x424): undefined reference to `ChoosePixelFormat@8'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x437): undefined reference to `SetPixelFormat@12'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xc38): undefined reference to `DescribePixelFormat@16'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xdf4): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xe25): undefined reference to `DescribePixelFormat@16'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xe4d): undefined reference to `SetPixelFormat@12'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1414): undefined reference to `DescribePixelFormat@16'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x14f0): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x154c): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(egl_context.c.obj):egl_context.c:(.text+0xb96): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(egl_context.c.obj):egl_context.c:(.text+0xb9e): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(egl_context.c.obj):egl_context.c:(.text+0x1178): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(egl_context.c.obj):egl_context.c:(.text+0x1184): more undefined references to `__mingw_free' follow
C:\MinGW\lib/libglfw3.a(input.c.obj):input.c:(.text+0x22ee): undefined reference to `__mingw_realloc'
C:\MinGW\lib/libglfw3.a(input.c.obj):input.c:(.text+0x1116): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0xbf): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0xca): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0xd5): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0xfc): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x107): more undefined references to `__mingw_free' follow
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x29d): undefined reference to `__mingw_realloc'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x36f): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x37a): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x385): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3ac): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3b7): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3c2): more undefined references to `__mingw_free' follow
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x113): undefined reference to `CreateDCW@16'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x16b): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1c6): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1fa): undefined reference to `DeleteDC@4'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x21f): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x35c): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x373): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x621): undefined reference to `__mingw_free'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x98d): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x9a4): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xb1d): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xb34): undefined reference to `GetDeviceCaps@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xdd6): undefined reference to `__mingw_realloc'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf76): undefined reference to `CreateDCW@16'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf8b): undefined reference to `GetDeviceGammaRamp@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf96): undefined reference to `DeleteDC@4'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x10eb): undefined reference to `CreateDCW@16'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x10fc): undefined reference to `SetDeviceGammaRamp@8'
C:\MinGW\lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1107): undefined reference to `DeleteDC@4'
collect2.exe: error: ld returned 1 exit status

How to fix it?

Compilation with MinGW on Windows is advanced, I would recommend using Visual Studio Community edition (free).

Do read the GLFW Build Guide section “With MinGW or Visual C++ on Windows”.

You might find it easier link against the dynamic library version of GLFW (glfw3dll) when using MinGW, if you do make sure to define GLFW_DLL before any including GLFW. Alternatively you might find building the code and your application with CMake is simpler, do check out this basic GLFW CMake starter example (note that I haven’t tested it on MinGW).

Note that your main.c code is not a well formed GLFW program, please see the basic example: Documentation | GLFW