Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 998
mas4 Avatar asked Oct 26 '15 22:10

mas4


3 Answers

This problem can be solved through installing libsdl2-image-dev package:

apt install libsdl2-image-dev
like image 149
user6039980 Avatar answered Oct 24 '22 01:10

user6039980


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.

like image 38
mas4 Avatar answered Oct 23 '22 23:10

mas4


From SDL documentation, it says that add 'lSDL_image' to the end of the compile line.

    cc -o myprogram mysource.o `sdl-config --libs` -lSDL_image

or

    gcc -o myprogram mysource.c `sdl-config --libs` -lSDL_image

Here is the reference -> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html Section 2.2 Compiling.

So for SDL2, you just need to change 'lSDL_image' to 'lSDL2_image'.

like image 2
erolrecep Avatar answered Oct 24 '22 00:10

erolrecep