Search code examples
cmingwmingw-w64glew

How to add a custom library (e.g. glew) to mingw-w64?


I'm using windows and my goal is to add the glew library (http://glew.sourceforge.net/index.html) to mingw. I have downloaded mingw-w64 via GitHub (https://github.com/mstorsjo/llvm-mingw/releases/tag/20210423). It comes with a "bin", "lib" and "include" folder. Within the "bin" folder I do "make" to execute my project's makefile which inlcudes the line

LDLIBS=-lm -lGL -lGLEW -lglfw

I have copied "glew32.lib" to "mingw/lib", "GL/glew.h" and "GL/wglew.h" to "mingw/include/GL" and "bin/glew32.dll" to "mingw/bin".

In my source code i have included the header file with

#include <GL/glew.h>

When i do "make" i get an error on that line:

GL/glew.h: No such file or directory

How do you add custom libraries like glew to mingw?


Solution

  • When using a library use the -I compiler flag to tell the compiler where to find the include files (in your case the path containing the GL folder) and the -L linker flag to tell the linker where to find the libraries.

    To link with the library use the -l flag. The library itself is a a lib*.a file (or lib*.dll.a for shared libraries). For the -l flag the library is specified without prefix and suffix, so if your library is called libglew.a the flag will be -lglew.

    It is also possible to specified the full path to the lib*.a file instead of -L and -l flags, and with MinGW, if you have the .dll file you can even try to specify the path of the .dll file and the linker will know what to do.