SDL/SDL_image.h: No such file or directory

Viewed 71057

I'm trying to follow Lazy Foo's tutorials. But when I try to run one of his examples I get this compiler error:

error: SDL/SDL_image.h: No such file or directory

The compiler/linker is set up correctly, I'm using Code::Blocks on Windows XP.

However, the problem is simply that there are no SDL_image.h. I've checked in the folder that it supposedly should have been. I tried to download the SDL library again and checked again, still no SDL_image.h file. Where did the SDL_image.h file go?

The library I dowloaded was the 'SDL-devel-1.2.14-mingw32.tar.gz' under 'Development Libraries' for Win32 from this link: http://www.libsdl.org/download-1.2.php

8 Answers

For anyone who tries this, an update would be to actually add "-lSDL2_image" to your compilation line. Everyone else simply has -lSDL_image" which changed when SDL2 released. After that just go to the bin and add all of your .dll files to System32 and you should be all set!

SDL2 Windows Setup for (32b) that worked for me (C language):

  1. download SDL2_image-devel-2.0.5-mingw.tar.gz and SDL2_image-2.0.5-win32-x86.zip (32 chose other for 64) from here: https://www.libsdl.org/projects/SDL_image/.

  2. copy "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\include\SDL2\SDL_image.h" to you SDL folder where all your headers are my case "MinGW\include\SDL2".

  3. copy content from "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\bin" to "\MinGW\bin".

  4. copy content of : "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\lib" to "MinGW\lib"

  5. include header like this :

        #include <SDL2/SDL_image.h>
    
  6. link it in your makefile (see this '... -llibSDL2_image ...'):

        build:
            gcc -Wfatal-errors \
            -std=c99 \
            ./*.c \
            -I"C:\libsdl\include" \
            -L"C:\libsdl\lib" \
            -lmingw32 \
            -lSDL2main \
            -lSDL2 \
            -lSDL2 \
            -llibSDL2_image \
            -o example.exe
  1. Dummy CodeExample.c
     #include <SDL2/SDL.h>
     #include <SDL2/SDL_image.h>
     #include <SDL2/SDL_timer.h>
     #include <stdio.h>
    
    int main(int argc, char *args[])
    {
    
        // attempt to initialize graphics and timer system
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
        {
            printf("Error initializing SDL: %s\n", SDL_GetError());
        }
    
        // Declare pointers
        SDL_Window *window;
        SDL_Renderer *renderer;
        SDL_Texture *bitmapTex = NULL;
        SDL_Surface *bitmapSurface = NULL;
    
        // Create an application window with the following settings:
        window = SDL_CreateWindow(
            "An SDL2 window",       // window title
            SDL_WINDOWPOS_CENTERED, // initial x position
            SDL_WINDOWPOS_CENTERED, // initial y position
            840,                    // width, in pixels
            480,                    // height, in pixels
            SDL_WINDOW_OPENGL       // flags - see below
        );
    
        // Check that the window was successfully created
        if (!window)
        {
            // In the case that the window could not be made...
            printf("Could not create window: %s\n", SDL_GetError());
            SDL_Quit();
            return 1;
        }
    
        // create renderer which sets up graphics hardware
        Uint32 render_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
        renderer = SDL_CreateRenderer(window, -1, render_flags);
        if (!renderer)
        {
            printf("error creating renderer: %s\n", SDL_GetError());
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
        }
    
        // Load theimage into memory using SDL_Image library function
        bitmapSurface = IMG_Load("image.png");
        bitmapTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
    
        SDL_FreeSurface(bitmapSurface);
        if (!bitmapTex)
        {
            // In the case that the window could not be made...
            printf("Error creating texture: %s\n", SDL_GetError());
            SDL_DestroyRenderer(renderer);
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
        }
    
        // The window is open: could enter program loop here (see SDL_PollEvent())
        while (1)
        {
            SDL_Event e;
            if (SDL_PollEvent(&e))
            {
                if (e.type == SDL_QUIT)
                {
                    break;
                }
            }
    
            // Clear the window
            SDL_RenderClear(renderer);
            SDL_RenderCopy(renderer, bitmapTex, NULL, NULL);
            SDL_RenderPresent(renderer);
        }
    
        SDL_DestroyTexture(bitmapTex);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
    
        SDL_Quit();
    
        return 0;
    }

The SDL library is modular and only the core is distributed, by default, when you acquire the library. For SDL 1, this includes SDL, itself, and (for those writing SDL applications) SDL-devel; for SDL 2, the libraries are SDL2 and SDL2-devel. The corresponding include files in developer's applications are <SDL/SDL.h> and <SDL2/SDL.h>, with the include files having been installed in whatever location is standard for your system, when the *-devel libraries are acquired and installed.

The modules all follow a similar pattern, SDL_X, SDL_X-devel for SDL 1 and SDL2_X and SDL2_X-devel for SDL 2, for module X, with the corresponding developers' include files being <SDL/SDL_X.h> and <SDL2/SDL_X.h>. For instance, for the image module, X = image, the libraries are SDL_image, SDL_image-devel, SDL2_image, SDL2_image-devel, and the include files are <SDL/SDL_image.h> and <SDL2/SDL_image.h>.

The modules are: "image" (as just mentioned) for handling images in the different standard formats (e.g. PNG); "mixer", for handling the different audio file formats, "gfx" for graphics drawing primitives, "net" for networked applications, "rtf" for Rich Text Format, "ttf" for the font-handling (ttf stands for "TrueTypeFont").

The Source Code for SDL is over here:

https://github.com/orgs/libsdl-org/repositories?type=all

Related