'"SDL.h" no such file or directory found' when compiling

argoneus picture argoneus · May 7, 2012 · Viewed 101.9k times · Source

Here's a piece of my current Makefile:

CFLAGS = -O2 -Wall -pedantic -std=gnu++11 `sdl-config --cflags --libs` -lSDL_mixer

I have libsdl installed properly, SDL.h is in /usr/include/sdl where it belongs, but it just won't compile. I also have the line #include "SDL.h" in my .h files, but still no go.

Anyone knows why?

Answer

StackAttack picture StackAttack · Dec 2, 2016

For Simple Direct Media Layer 2 (SDL2), after installing it on Ubuntu 16.04 via:

sudo apt-get install libsdl2-dev

I used the header:

#include <SDL2/SDL.h>  

and the compiler linker command:

-lSDL2main -lSDL2 

Additionally, you may also want to install:

apt-get install libsdl2-image-dev  
apt-get install libsdl2-mixer-dev  
apt-get install libsdl2-ttf-dev  

With these headers:

#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>  

and the compiler linker commands:

-lSDL2_image 
-lSDL2_ttf 
-lSDL2_mixer