c++ubuntusdlsdl-2sdl-image

SDL2_image not found


I am trying to compile the following code which has the headers:

#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>

However after running the following makefile:

g++ -std=c++11 src/main.cpp -lSDL2 -lSDL2_image

I get the following error:

fatal error: SDL2_image/SDL_image.h: No such file or directory
#include <SDL2_image/SDL_image.h>

Any suggestions? Not entirely sure about my installation of SDL_image. I am running this on Ubuntu.


Solution

  • Run apt-file search SDL_image.h The result will tell you the location of the include file.

    For instance, /usr/include/SDL2/SDL_image.h was returned. So, when you want to include SDL_image.h, write everything after the include/ in between < >.

    Thus, includes should look like the following:

    #include <SDL2/SDL.h>
    #include <SDL2/SDL_image.h>
    

    See the question's comments for the original discussion regarding this solution.