Hi guys need some help getting MinGW to link GLFW's libraries. I can't find any answers on the web or rather not any that I can understand. I have tried to specify the path to the libs folder using -L and I have added the lib's and include's to MinGW's.
I have even tried changing the names of the libs. The compiler never complains about not finding the headers but the linker says it cant find whatever lib I specify.
I have been at GLFW's site but I'm afraid that I don't understand much of what they are trying to tell me. I'm on windows7 using MinGW via the command line since I can't get it to work with Code::Blocks either. I have tried following the installation instructions on opengl-tutorial.org but that sadly starts to complain about something to do with ANT which I don't understand at all. So I think I have a better chance at getting it to work via the command line.
I have tried:
g++ test.cpp -lglfw or g++ test.cpp -LC:\GLFW\lib -lglfw
into the command line.
A simple investigate of the GLFW3's lib-mingw
directory holds the answer for your question. Say you've GLFW3's binary package, from here (one of glfw-3.0.3.bin.WIN64.zip
or glfw-3.0.3.bin.WIN32.zip
depending on your toolchain). Extracting it should've given a directory lib-mingw
amongst others. This directory contains:
- libglfw3.a
- glfw3dll.a
- glfw3.dll
Thus the library name is glfw3
and not just glfw
. So when passing it to the linker, you've to pass -lglfw3
i.e. if you want to statically link to it. If you want to link to it dynamically, then just pass glfw3dll.a
; adding the -l
will lead to the linker prefixing it with lib
and suffixing it with .a
(see Django's answer).
I managed to make mingw32 and GLFW3 to work together.
- Be sure you have consistent librairies (32 or 64 bits) (it wasn't my case)
- Rename glfw3dll.a to libglfw3dll.a
- Add you lib*.a from glfw to %MINGW_BASE%\lib and include files to %MINGW_BASE%\include
- Compile and link using g++ test.cpp -lglfw3 -lopengl32
- To run it, be sure to add glfw3.dll in System32 or/and SysWOW64
It worked for me
Hope it will help,