# Undefined reference errors when linking GLFW with MinGW

**URL:** <https://discourse.glfw.org/t/undefined-reference-errors-when-linking-glfw-with-mingw/1771>\
**Category:** support\
**Created:** [February 18, 2021, 4:51pm UTC](https://discourse.glfw.org/t/undefined-reference-errors-when-linking-glfw-with-mingw/1771 "2021-02-18T16:51:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ripytide](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ripytide/32/470_2.png) [@Ripytide](https://discourse.glfw.org/u/Ripytide)\
**Post date:** [February 18, 2021, 4:51pm UTC](https://discourse.glfw.org/t/undefined-reference-errors-when-linking-glfw-with-mingw/1771/1 "2021-02-18T16:51:55Z")

</div>

Hello, I am trying to build a super simple test program with GLFW on window 10 with gcc and MinGW using the static libraries, but I keep getting undefined referenced errors.  
**test.c:**

```auto
#include <glfw3.h>
int main() {
    glfwInit();
    glfwTerminate();
    return 0;
}

```

And here is what I want to do:

```auto
gcc -c test.c -Iinclude
gcc test.o -lglfw3 -lgdi32 -o test.exe

```

And here is the error is gives me:

```auto
test.o:test.c:(.text+0xc): undefined reference to `glfwInit'
test.o:test.c:(.text+0x11): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

```

List of things I have tried:

- I have tried both the 32bit and 64bit glfw3 static libraries.
- I have tried also linking other libraries references on the documentation I specified earlier such as kernel32 and user32 with no change to the error.
- I have tried changing the order in which I link libraries.

I am slightly confused with this error, are the definitions for `glfwInit` and `glfwTerminate` not somewhere in the `libglfw3.a` ? Surely they are? But, if so why does the linker throw undefined reference error?

---

<div class="post-metadata">

**Author:** ![Ripytide](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ripytide/32/470_2.png) [@Ripytide](https://discourse.glfw.org/u/Ripytide)\
**Post date:** [February 18, 2021, 5:37pm UTC](https://discourse.glfw.org/t/undefined-reference-errors-when-linking-glfw-with-mingw/1771/2 "2021-02-18T17:37:39Z")

</div>

So I understand that this error is happening in the linking stage of the compilation process as the object files compile fine. While reading [this post](https://discourse.glfw.org/t/linking-glfw-on-the-command-line-not-working/1730/9) I saw that [mmozeiko](https://discourse.glfw.org/u/mmozeiko) gave commented a gcc command where the usual link flag `-l` was ignored so instead of `gcc test.c -lglfw3` he wrote `gcc test.c libglfw3.a` I tried this and below and behold, it fixes my issue. Why is this the case? I understand that this is something to do with gcc and not glfw so I won’t be offended if no one responds.
