SDL/SDL_image.h: No such file or directory
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
You need to install SDL_image separately. It's not shipped with SDL.
You need to install SDL_image library like mentioned in the other answers, if you are on a Debian based systems you can simply install with the following command:
sudo apt-get install libsdl-image1.2-dev
In the third tutorial of lazyfoo is completely explained.
Basically, you must add "-lSDL_image" to the compilation line.
In your case as you are using windows, then you should first install sdl_image
and then
#include <SDL_image.h>
not
#include <SDL/SDL_image.h>
If you were using linux and your sdl-image
package is installed to /usr/include/SDL
then you need to use
#include <SDL_image.h>
In most cases when you install from source in linux. Your package may not be resident in /usr/include/SDL
In these kind of situation, I use
#include <SDL/SDL_image.h>
and it works
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!
You have to Download "SDL_image-devel-1.2.4-VC6.zip" For code blocks download link » http://www.libsdl.org/projects/SDL_image/release/SDL_image-devel-1.2.4-VC6.zip
copy the files present in the include folder that you will find inside the zip file after extraction.And paste it to the C:\SDL\include\SDL in my case or to the directory where your other SDL *.h are present.
Similary, Copy the files present in the lib folder of the zip file and paste it to C:\SDL\lib or to the folder where other lib files are present.. Then copy all the *.dll files present in the archive to the C:\windows\system32 Further you have to add "-lSDL_image" to the compilation line by openning settings > compiler& debugger > linker.
Then open a empty file project and add empty file to the project then #include "SDL\SDL_image.h" Hope it works for you !!
Or
First download SDL_image-devel-1.2.4-VC6.zip from above given link and Goto link >> http://www.lazyfoo.net/SDL_tutorials/lesson03/windows/codeblocks/index.php for more detailed explaination.
SDL2 Windows Setup for (32b) that worked for me (C language):
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/.
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".
copy content from "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\bin" to "\MinGW\bin".
copy content of : "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\lib" to "MinGW\lib"
include header like this :
#include <SDL2/SDL_image.h>
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
- 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
精彩评论