Cannot run GLFW example on Windows 10

I’m on Windows 10 and using MinGW to use gcc. I’m using the code on http://www.glfw.org/documentation.html right now. I’m compiling it with gcc main.c -o main.exe -lglfw3.
But then I get this:
(I replaced my long path behind main.c just with “longpath”)

longpath:main.c:(.text+0x17): undefined reference to `glfwInit'
longpath:main.c:(.text+0x51): undefined reference to `glfwCreateWindow'
longpath:main.c:(.text+0x5f): undefined reference to `glfwTerminate'
longpath:main.c:(.text+0x71): undefined reference to `glfwMakeContextCurrent'
longpath:main.c:(.text+0x7f): undefined reference to `_imp__glClear@4'
longpath:main.c:(.text+0x8f): undefined reference to `glfwSwapBuffers'
longpath:main.c:(.text+0x94): undefined reference to `glfwPollEvents'
longpath:main.c:(.text+0x9f): undefined reference to `glfwWindowShouldClose'
longpath:main.c:(.text+0xa8): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

I also tried running with gcc main.c -o main.exe -lglfw3 -lglfw3dll. But that gave the same result.
So it’s probably missing something.

What should I do?

My topic pretty much equals Linking libraries if that helps

Are you using a 32-bit or 64-bit version of MinGW? If the former then you need to link with the 32-bit binaries, and if the later with the 64-bit ones.

Also check out the documentation on compiling programs which use GLFW.

2 Likes

Thank you so much man! I’m using MinGW64 now. After I switched to MinGW64 I still got some errors. But this time other errors. I fixed them by compiling it with
gcc main.c -o main.exe -lglfw3 -lglfw3dll -lopengl32 -lgdi32
instead of just
gcc main.c -o main.exe -lglfw3 -lglfw3dll

Excellent, glad you have this resolved!