Lib GLFW3.dll crashing on Windows 7


#1

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?


#2

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


#3

The gcc compiler set is MinGW.


#4

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 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

#5

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).


#6

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. :slight_smile:


#7

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


#8

Glad you got it working (no pun intended). 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?


#9

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!