i686-w64-mingw32-gcc/x86_64-w64-mingw32-gcc not working GLFW

440 Views Asked by At

How do I fix this error?

None-of-your-business@penguin:~/None-of-your-business$ x86_64-w64-mingw32-gcc -o bin/EreecliseWin64.exe src/main.c
src/main.c:4:10: fatal error: GLFW/glfw3.h: No such file or directory
    4 | #include <GLFW/glfw3.h>
      |          ^~~~~~~~~~~~~~

I tried this.

None-of-your-business@penguin:~/None-of-your-business$ x86_64-w64-mingw32-gcc -o bin/EreecliseWin64.exe src/main.c -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -ldl -lm
src/main.c:4:10: fatal error: GLFW/glfw3.h: No such file or directory
    4 | #include <GLFW/glfw3.h>
      |          ^~~~~~~~~~~~~~

I have GLFW installed

1

There are 1 best solutions below

0
Brecht Sanders On

Your command is a short form that combines both compiler and linker step:

x86_64-w64-mingw32-gcc -o bin/EreecliseWin64.exe src/main.c

For troubleshooting purposes and overall clarity during the build process I recommend you split this in the 2 seperate steps, like this:

x86_64-w64-mingw32-gcc -c -o bin/main.o src/main.c
x86_64-w64-mingw32-gcc -o bin/EreecliseWin64.exe src/main.o

The first line above is the compiler step, and you should add the compiler flags needed for glfw3 to it. If everything is properly installed you should be able to get these flags by running pkg-config --cflags glfw3.

The second line above is the linker step, and you should add the linker flags needed for glfw3 to it. If everything is properly installed you should be able to get these flags by running pkg-config --lib glfw3.

x86_64-w64-mingw32-gcc -c -o bin/main.o src/main.c $(pkg-config -cflags glfw3)
x86_64-w64-mingw32-gcc -o bin/EreecliseWin64.exe src/main.o $(pkg-config --libs glfw3)

If pkg-config doesn't work, either try by pointing PKG_CONFIG_PATH to the path containing glfw3.pc (e.g. PKG_CONFIG_PATH=/usr/lib/pkgconfig/glfw3.pc), or specify the flags manually like this:

x86_64-w64-mingw32-gcc -c -o bin/main.o src/main.c -I/usr/include
x86_64-w64-mingw32-gcc -o bin/EreecliseWin64.exe src/main.o -L/usr/lib -lglfw3

Replace /usr in the examples above with the proper location of your installation of glfw3 for the x86_64-w64-mingw32 platform.

If you're cross-compiling (targeting Windows while building on Linux) it's important you have and use a Windows build of glfw3.