16

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.

mas4
  • 989
  • 1
  • 8
  • 20
  • 1
    I checked my code and it has #include . Try , maybe that helps. – Karlis Olte Oct 26 '15 at 23:03
  • You need to tell us in which directory `SDL_image.h` is installed. Once we know that, we can tell you how to add the relevant compilation option to your makefile – Daniel Strul Oct 26 '15 at 23:07
  • after running `apt-file search SDL_image.h` I get the following: `emscripten: /usr/share/emscripten/system/include/SDL/SDL_image.h` `libsdl-image1.2-dev: /usr/include/SDL/SDL_image.h` `libsdl2-image-dev: /usr/include/SDL2/SDL_image.h` – mas4 Oct 27 '15 at 02:54
  • @KarlisOlte Thank you, your suggestion worked! Not sure why exactly (guessing it's referring to the [folder_name]/[file_name]). I appreciate the help. – mas4 Oct 27 '15 at 04:23

4 Answers4

17

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

apt install libsdl2-image-dev
user6039980
  • 3,108
  • 8
  • 31
  • 57
4

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.

mas4
  • 989
  • 1
  • 8
  • 20
2

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'.

erolrecep
  • 66
  • 4
1

For Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks you've got the add both Runtime Binaries and Development Libraries to the compiler and linker. Or else, you'll get the error SDL2_image not found, even with having the dll in your program's directory, this occurs. Hopefully others find this helpful; I had to figure it out myself. Example: If your resources are separate, you'll be adding the two plus your standard SDL2 paths to your compiler and linker. Warning: SDL2_image.h has it's headers assuming that the headers are in the same folder as the SDL2 framework. If you get errors about the image header, include the sub-folder SDL2 from SDL framework in the path and then you should be including SDL2 in the program as: include <SDL.h> rather than include <SDL2/SDL.h>.

dstackflow
  • 77
  • 1
  • 7