# Lib GLFW3.dll crashing on Windows 7

**URL:** <https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944>\
**Category:** support\
**Created:** [July 10, 2017, 1:16pm UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944 "2017-07-10T13:16:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrMemory](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/drmemory/32/109_2.png) [@DrMemory](https://discourse.glfw.org/u/DrMemory)\
**Post date:** [July 10, 2017, 1:16pm UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/1 "2017-07-10T13:16:06Z")

</div>

I have a serious setup problem!

I downloaded the 3.2.1 Win32 binaries and tried compiling the “Hello World” example (from the Documentation front page).

This was compiled and linked with gcc 5.3.

The test program calls _**glfwInit()**_ ok, but crashes with an access violation when it calls _ **gflwCreateWindow** _.

Code:

> #include “…/include/GL/gl.h”  
> #include “…/include/GL/glfw3.h”  
> int main(void)  
> {  
> GLFWwindow\* window;

> ```
> /* Initialize the library */
> if (!glfwInit()) return -1;
> 
> ```

> ```
> /* Create a windowed mode window and its OpenGL context */
> window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
> 
> ```

Compile & link (from CMD window):

> gcc -c Test.c -o Test.o  
> gcc -o Test.exe Test.o GLFW3.dll OpenGL32.dll

Can anybody help?

---

<div class="post-metadata">

**Author:** ![tombsar](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@tombsar](https://discourse.glfw.org/u/tombsar)\
**Post date:** [July 10, 2017, 1:20pm UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/2 "2017-07-10T13:20:10Z")

</div>

How are you running gcc on Windows? mingw? mingw-w64? cygwin?

---

<div class="post-metadata">

**Author:** ![DrMemory](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/drmemory/32/109_2.png) [@DrMemory](https://discourse.glfw.org/u/DrMemory)\
**Post date:** [July 10, 2017, 1:22pm UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/3 "2017-07-10T13:22:22Z")

</div>

The gcc compiler set is MinGW.

---

<div class="post-metadata">

**Author:** ![tombsar](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@tombsar](https://discourse.glfw.org/u/tombsar)\
**Post date:** [July 10, 2017, 1:50pm UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/4 "2017-07-10T13:50:35Z")

</div>

Firstly, make sure you are using the correct dlls (32 bit only, in the MinGW folder of the glfw binary download).

Since you have put dlls in the compile line, I presume you want to link dynamically rather than statically. I am not used to putting .dlls directly in the compile line, however. It might work, but I have only ever used `-lglfw` and similar.

This link [http://www.glfw.org/docs/latest/build\_guide.html#build\_link\_win32](http://www.glfw.org/docs/latest/build_guide.html#build_link_win32) says that in order for dynamic linking to work, you need to define `GLFW_DLL` somewhere, either in the source code or in the compile line.

Do the following lines work for you?

```
gcc -c Test.c -o Test.o -DGLFW_DLL
gcc -o Test.exe Test.o -lglfw3dll -lopengl32
```

---

<div class="post-metadata">

**Author:** ![DrMemory](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/drmemory/32/109_2.png) [@DrMemory](https://discourse.glfw.org/u/DrMemory)\
**Post date:** [July 10, 2017, 2:06pm UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/5 "2017-07-10T14:06:41Z")

</div>

Thanks for that suggestion, but sadly that made no difference.

Regarding DLL linking directly, this typically works fine, you don’t need a LIB file (which is just a description of what the DLL exports).

---

<div class="post-metadata">

**Author:** ![DrMemory](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/drmemory/32/109_2.png) [@DrMemory](https://discourse.glfw.org/u/DrMemory)\
**Post date:** [July 11, 2017, 1:19am UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/6 "2017-07-11T01:19:15Z")

</div>

Success!!!

I have been working on this all night. The problem was with the OPENGL32 interface on Windows.

The “Hello World” sample includes a call to _glClear()_ which is an Open GL function. I commented that out and the program worked.

It was only when I downloaded the GLFW source and re-built GLFW3.dll that I discovered there was a set of test programs which used GLAD to reference OpenGL functions. By using the same methods I got “Hello World” working with the _glClear_ call.

The GLAD method is actually described in “Getting Started”, but it was only later that I found my way there.

It appears that on Windows 7, at least, you can’t call OpenGL functions directly, you have to use an extension loader library like GLAD.

Anyway, all is now well, and I have finally got to first base!

I can now get on with the real objective of this exercise, which is to get the _Chipmunk_ demo programs working. 🙂

---

<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:** [July 11, 2017, 1:35am UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/7 "2017-07-11T01:35:38Z")

</div>

You can call OpenGL functions directly on Windows 7. There was something else wrong in your code to cause this crash.

---

<div class="post-metadata">

**Author:** ![tombsar](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@tombsar](https://discourse.glfw.org/u/tombsar)\
**Post date:** [July 11, 2017, 8:45am UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/8 "2017-07-11T08:45:45Z")

</div>

Glad you got it working (no pun intended). [mmozeiko](http://discourse.glfw.org/u/mmozeiko) is right, though: legacy OpenGL functions such as `glClear` are always accessible through opengl32.dll without using a function loading library.

There is something that confuses me: in your original post you said that the crash was on the call to `glfwCreateWindow`, but your latest post says that commenting out `glClear` is what allowed the program to run. Is that really the only change you made?

---

<div class="post-metadata">

**Author:** ![DrMemory](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/drmemory/32/109_2.png) [@DrMemory](https://discourse.glfw.org/u/DrMemory)\
**Post date:** [July 11, 2017, 10:03am UTC](https://discourse.glfw.org/t/lib-glfw3-dll-crashing-on-windows-7/944/9 "2017-07-11T10:03:27Z")

</div>

Ok, I have tracked the root cause of the problem. You are both right of course, about direct calls to _OpenGL32_. The problem was not in the code, it was environmental.

At the beginning when I got a link error with _glClear_ I made a local copy of _OpenGL32.dll_ to link against. That’s fine for linking purposes, but at run-time it’s a disaster.

The original program now works just fine.

Thanks to both of you for your input!
