9

我正在尝试编译以下具有标头的代码:

#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>

但是在运行以下生成文件后:

g++ -std=c++11 src/main.cpp -lSDL2 -lSDL2_image

我收到以下错误:

fatal error: SDL2_image/SDL_image.h: No such file or directory
#include <SDL2_image/SDL_image.h>

有什么建议么?不完全确定我安装的 SDL_image。我在 Ubuntu 上运行它。

4

4 回答 4

11

这个问题可以通过安装libsdl2-image-dev包来解决:

apt install libsdl2-image-dev
于 2017-10-21T03:15:31.413 回答
3

运行apt-file search SDL_image.h 结果会告诉你包含文件的位置。

例如,/usr/include/SDL2/SDL_image.h被退回。所以,当你想包含 时,在中间SDL_image.h写下所有内容。include/< >

因此,包含应如下所示:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

有关此解决方案的原始讨论,请参阅问题的评论。

于 2015-10-27T18:04:37.840 回答
2

从 SDL 文档中,它说将“lSDL_image”添加到编译行的末尾。

    cc -o myprogram mysource.o `sdl-config --libs` -lSDL_image

或者

    gcc -o myprogram mysource.c `sdl-config --libs` -lSDL_image

这是参考 -> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html 第 2.2 节编译。

因此,对于 SDL2,您只需将 'lSDL_image' 更改为 'lSDL2_image'。

于 2019-12-05T03:55:49.713 回答
0

因为Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks您已经添加了编译器和链接器Runtime BinariesDevelopment Libraries否则,您将收到错误消息SDL2_image not found,即使dll在您的程序目录中有 ,也会发生这种情况。希望其他人觉得这有帮助;我必须自己弄清楚。示例:如果您的资源是分开的,您将添加两个加上您的标准SDL2路径到您的编译器和链接器。警告:SDL2_image.h 有它的标题,假设标题与 SDL2 框架位于同一文件夹中。如果您收到有关图像标题的错误,请在路径中包含来自 SDL 框架的子文件夹SDL2,然后您应该SDL2在程序中包含:include <SDL.h>而不是include <SDL2/SDL.h>.

于 2018-11-03T08:34:17.243 回答