# Setting up GLFW with MinGW

**URL:** https://discourse.glfw.org/t/setting-up-glfw-with-mingw/1684
**Category:** support
**Created:** [October 28, 2020, 4:16pm UTC](https://discourse.glfw.org/t/setting-up-glfw-with-mingw/1684 "2020-10-28T16:16:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![77Z](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/77z/32/423_2.png) [@77Z](https://discourse.glfw.org/u/77Z)
#### Post date: [October 28, 2020, 4:16pm UTC](https://discourse.glfw.org/t/setting-up-glfw-with-mingw/1684/1 "2020-10-28T16:16:58Z")

</div>

Hello! My name is Vince, and I’ve been trying to setup GLFW on Windows 10 with MinGW for a project of mine, I included GLFW/glfw3.h just fine, and I’ve done the linking for MinGW just fine also, however, when I try and compile my program I get an error saying that some GLFW functions aren’t defined. I don’t have access to the source right now as I’m typing this on a Chromebook, but later I will be able to give the Makefile and others. Any help is appreciated, thanks in advance,

Vince

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [October 28, 2020, 5:58pm UTC](https://discourse.glfw.org/t/setting-up-glfw-with-mingw/1684/2 "2020-10-28T17:58:36Z")

</div>

Hi Vince,

Welcome to the GLFW forum!

Have you read the MinGW Building Applications notes?

> **[GLFW: Building applications](https://www.glfw.org/docs/latest/build_guide.html#build_link_win32)**

You might find that using this Cmake GLFW Starter helpful, though I’ve not tested it with MinGW:

> **[juliettef/GLFW-CMake-starter](https://github.com/juliettef/GLFW-CMake-starter)**
>
> Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS. - juliettef/GLFW-CMake-starter

Cheers,  
Doug.

---

<div class="post-metadata">

### Author: ![77Z](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/77z/32/423_2.png) [@77Z](https://discourse.glfw.org/u/77Z)
#### Post date: [October 28, 2020, 9:23pm UTC](https://discourse.glfw.org/t/setting-up-glfw-with-mingw/1684/3 "2020-10-28T21:23:26Z")

</div>

Thanks Doug, I’ve seen this and it didn’t do much. But here’s the makefile output if it’s any use  
❯ make -f .\Makefile.win  
g++ -Iinclude -Llib-mingw-w64 -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 Source/main.cpp Source/vlib.cpp -o dist/out.exe  
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x30): undefined reference to `glfwSetWindowShouldClose' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x12d): undefined reference to `glfwInit’  
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x165): undefined reference to `glfwCreateWindow' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x175): undefined reference to `glfwTerminate’  
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x18b): undefined reference to `glfwMakeContextCurrent' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x19e): undefined reference to `glfwSetKeyCallback’  
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1ac): undefined reference to `__imp_glClear' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1ba): undefined reference to `glfwSwapBuffers’  
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1bf): undefined reference to `glfwPollEvents' C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1cb): undefined reference to `glfwWindowShouldClose’  
C:\Users\Owner\AppData\Local\Temp\cc0gresO.o:main.cpp:(.text+0x1d9): undefined reference to `glfwTerminate' c:/users/owner/documents/winbuilds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Owner\AppData\Local\Temp\cc0gresO.o: bad reloc address 0x18 in section `.xdata’  
collect2.exe: error: ld returned 1 exit status  
make: \*\*\* [all] Error 1

---

<div class="post-metadata">

### Author: ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)
#### Post date: [October 28, 2020, 9:46pm UTC](https://discourse.glfw.org/t/setting-up-glfw-with-mingw/1684/4 "2020-10-28T21:46:48Z")

</div>

GNU linker searches dependencies in libraries/files from command-line only left to right. So if your main.cpp depends on functions in glfw or opengl, then it must come first in command-line, not after glfw/opengl:

```
g++ -Iinclude -Llib-mingw-w64 Source/main.cpp -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 Source/vlib.cpp -o dist/out.exe

```

Alternative is to use `-Wl,--start-group` that will make it search dependencies in any order:

```
g++ -Iinclude -Llib-mingw-w64 -Wl,--start-group -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 Source/main.cpp Source/vlib.cpp -o dist/out.exe -Wl,--end-group
```
