Search code examples
gccmingwsdlgit-bash

Cannot find <SDL.h>


I'm current following the LazyFoo tutorials for SDL2 however I've been having trouble getting SDL2 set up using this link https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/mingw/index.php. I'm using C instead of C++ and MinGW 64-bit.

My gcc compiler can't find the SDL.h header file even though I'm including the directory using the -I flag that contains the SDL.h file. I'm currently using GitBash as my Terminal and VS code as my text editor.

Here is an example of my terminal command and output

/z/programming/c/lazy_foo_sdl/01_hello_SDL> gcc 01_hello_SDL.c -IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o 01_hello_SDL
01_hello_SDL.c:4:10: fatal error: SDL.h: No such file or directory
 #include <SDL.h>
          ^~~~~~~
compilation terminated.

I really have no idea what could be the issue so apologies in advance if I'm not providing enough detail.


Solution

  • If you're in bash you have to follow bash rules and escape your backslashes:

    -IC:\\mingw_dev_lib\\include\\SDL2
    

    Or don't use backslashes at all and use bash-on-windows notation:

    -I/c/mingw_dev_lib/include/SDL2
    

    And to prevent at least one future question - don't name cleanup function close as said tutorial suggests. Just don't.