我正在使用 Debian 并且我成功下载了 SDL_image.h。 (sudo apt-get install libsdl2-image-dev)
我编写了一个简单的代码来判断它是否能看到 PNG 图像,但出现错误。
代码:
#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;
}
我在命令行编译如下
gcc SDL_learnT.c -w -lSDL2 -o SDL_learnT
我收到错误 =“致命错误:SDL_image.h 没有这样的文件或目录”
我尝试执行以下操作,但结果没有改变
#include
答案 0 :(得分:1)
编辑:从您最近的编辑来看,您似乎[已经]解决了您的问题,因此以下内容可能没有实际意义。
为 SDL2_image
安装开发包[看来您已经完成了--叹气]。
在 Fedora 上,这是:
sudo dnf install SDL2_image-devel
在 ubuntu 上:
sudo apt install libsdl2-image-dev
在 pkg-config
行中使用 gcc
(例如):
gcc -o program program.c `pkg-config --cflags --libs` SDL2_image
或sdl2-config
:
gcc -o program program.c `sdl2-config --cflags --libs` -lSDL2_image
无论如何,正确的包含是:
#include <SDL2/SDL_image.h>
你应该能够做到:
find -xdev /usr -name SDL_image.h
find -xdev /usr/local -name SDL_image.h
或者,一些 ls
命令。
然后,与 pkg-config
输出进行比较。
最后的手段......我过去在使用 SDL2 和 ubuntu(仿生)时遇到过麻烦。最终,我卸载了标准包并从源包重新构建/重新安装。
加班:
IMG_Load
返回表面,而不是纹理:
SDL_Texture *image = IMG_Load(fileName);
应该
SDL_Surface *image = IMG_Load(fileName);
这里:
if (SDL_Init(SDL_INIT_VIDEO) < 0) printf("ERROR SDL_Init() - VIDEO");
仅仅通知错误是不够的,您应该退出(或至少跳过所有 SDL 函数),一个更好的方法:
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
SDL_Log("SDL_Init: %s", SDL_GetError());
exit(EXIT_FAILURE);
}
答案 1 :(得分:0)
解决方案
It should be <SDL2/SDL_image.h> not <SDL_image.h>
Compiling with gcc should be as follows (Command Line)
$gcc FILENAME.c -o OUTNAME -w -lSDL2 -lSDL2_image