How to build OpenGL + GLEW + GLFW program so that glfw3.dll won't be needed in the folder with exe?

StackOverflow https://stackoverflow.com/questions/22846707

Question

I have compiled and executed a simple OpenGL + GLEW + GLFW program that I have copied from a tutorial. I used C++ and CodeBlocks 13.12 on a Win 7 x64 machine.

The program executes only if there is glfw3.dll file present in the bin/Debug folder, where the exe is located. Otherwise it gives error : The program cannot be executed because glfw.dll is not found in the system. I used the default CodeBlocks settings.

How do I build the program so that glfw3.dll won't be needed in the folder with exe file, but instead built into the program ?

Was it helpful?

Solution

Statically link GLFW:

The static version of the GLFW library is named glfw3. When using this version, it is also necessary to link with some libraries that GLFW uses.

When linking a program under Windows that uses the static version of GLFW, you must link with opengl32. If you are using GLU, you must also link with glu32.

OTHER TIPS

I use Nuwen's mingw distro and compile with this: g++ glfwtest.cpp -o glfwtest.exe -lglew32 -lglfw3 -lopengl32 -lgdi32

From the website: The static version of the GLFW library is named glfw3. When using this version, it is also necessary to link with some libraries that GLFW uses.

When linking a program under Windows that uses the static version of GLFW, you must link with opengl32. On some versions of MinGW, you must also explicitly link with gdi32, while other versions of MinGW include it in the set of default libraries along with other dependencies like user32 and kernel32. If you are using GLU, you must also link with glu32.

http://www.glfw.org/docs/latest/build.html#build_link_win32

So in my case I have to link gdi32.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top