How do I compile the example on mingw-w64?

Hello everyone, I am trying to compile the sample code from the site but I get this error:
glfw.cpp:1:10: fatal error: GLFW/glfw3.h: No such file or directory
#include <GLFW/glfw3.h>
compilation terminated.

I don’t know if I installed glfw correctly but the contents of the glfw include folder I copied to the mingw64 include folder and the contents of lib-mingw-w64 folder I copied to the lib folder.
To compile the example i use only g++ glfw.cpp -o glfw?

i downloaded windows pre-compiled binaries glfw-3.3.bin.WIN64.

Hi @JamesCpp, welcome to the GLFW forums!

When compiling any program you need to tell the compiler the location of any include files or libraries by specifying search directories for these. To specify an include directory to search you use the -I[directory_name] option and for libraries you use -l[library] to specify the library and -L[library_dir] to specify the location. You don’t need to specify the library directory if you include the path to the library when specifying the library.

In your case if you correctly moved the include files and libraries you won’t need to specify the locations, but you will still need to specify the libraries. However it looks like you did not copy the include files to the correct location: the header glfw3.h should be in a directory GLFW in the MinGW include directory.

You will then need to ensure you link to GLFW and all the relevant libraries, which might be as follows:

g++ glfw.cpp -o glfw - lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32

You may not need the last three libraries, but it depends on your version of MinGW.

Let us know how this goes.

Hi @dougbinks, thanks

the version i use of mingw is MinGW-W64 GCC-8.1.0, x86_64-8.1.0-release-posix-seh-rt_v6-rev0.

Here are some pictures of how I copied the files:


I think you need to check that your install of MinGW is searching it’s own include path. To do that see their guide:

http://www.mingw.org/wiki/IncludePathHOWTO

Alternatively you can set the directory for the include search using the -I option:

g++ -IC:\mingw64\include\ glfw.cpp -o glfw - lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32

The include directory should have the folder GLFW inside, and in that folder you should have the file glfw3.h, so that the full path to glfw3.h is:

C:\mingw64\include\GLFW\glfw3.h

If you get errors from using this compile command, please copy and report the full text (not an image) of the compile output to your reply, thanks!

It worked!!
I’m happy!!

Thanks a lot @dougbinks, I’m on the c ++ learning path and you helped me a lot!

thanks :grinning:

Excellent, wiahing you a Happy New Year’s start to C++ and GLFW.