Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 584
James C Avatar asked Oct 19 '25 12:10

James C


2 Answers

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.

like image 167
genpfault Avatar answered Oct 21 '25 02:10

genpfault


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.

like image 38
Aaron Kyle Killeen Avatar answered Oct 21 '25 00:10

Aaron Kyle Killeen