I am using Debian and i downloaded SDL_image.h succesfully. (sudo apt-get install libsdl2-image-dev)
I wrote a simple code to tell if it sees PNG images, but I’m getting an error.
Code:
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL_image.h>
int main(){
if (SDL_Init(SDL_INIT_VIDEO) < 0) printf("ERROR SDL_Init() - VIDEO");
if (IMG_Init(IMG_INIT_PNG) < 0) prinft("ERROR IMG_Init() - PNG");
char fileName[50] = "im.PNG";
SDL_Texture *image = IMG_Load(fileName);
if (image == NULL) printf("ERROR image == NULL");
SDL_FreeSurface(image);
return 0;
}
I compiled it on the command line as follows
gcc SDL_learnT.c -w -lSDL2 -o SDL_learnT
And i am getting Error = "fatal error: SDL_image.h No such file or directory"
I tried to do the following but the result did not change
#include <SDL2_image.h> or #include <SDL2/SDL_image.h>
2
Answers
SOLUTION
Edit: It seems from your latest edit that you’ve [already] solved your problem, so the following may be moot.
Install the development package for
SDL2_image
[which it appears you’ve already done–sigh].On fedora, this is:
On ubuntu:
Use
pkg-config
in thegcc
lines (e.g.):or
sdl2-config
:In any case, the correct include is:
You should be able to do:
Or, some
ls
commands.Then, compare against the
pkg-config
output.A last resort … I’ve had trouble in the past with SDL2 and ubuntu (bionic). Ultimately, I uninstalled the standard packages and rebuilt/reinstalled from the source packages.
OT:
IMG_Load
returns a surface, not a texture:should be
And here:
It is not enough to inform about the error, you should exit (or at least skip all SDL functions), a better approach: